打开活动而不显示UIActivityViewController [英] Open activity without showing UIActivityViewController

查看:157
本文介绍了打开活动而不显示UIActivityViewController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在scrollView中拥有社交图标,当单击它时,其功能与在呈现UIActivityViewController后单击它们时的功能相同。 我不想呈现UIActivityViewController。



我知道这不可能,但是一个名为Yodel的应用程序确实这个(或类似的东西)我想做同样的事情。



点击Yodel中的图标与UIActivityViewController中的图标完全相同,所以它似乎以某种方式将它放在容器视图中(?)





以Whatsapp为例我试过以下内容:


  1. 使用Whatsapp API https://www.whatsapp.com/faq/en/iphone/23559013 ,网址为

      var whatsappURL = NSURL(字符串:whatsapp:// send?text = Hello%2C%20World!)! 
    如果UIApplication.sharedApplication()。canOpenURL(whatsappURL){
    UIApplication.sharedApplication()。openURL(whatsappURL)
    }


  2. 使用UIActivityViewController,但我希望它们都在scrollView中,如上图所示。


  3. 使用UIWebView打开URL Scheme,希望它能保留在UIWebView中。

      var whatsappURL = NSURL(字符串:whatsapp:// send?text = Hello%2C%20World!)! 
    如果UIApplication.sharedApplication()。canOpenURL(whatsappURL){
    UIApplication.sharedApplication()。openURL(whatsappURL)
    }

    self.view.addSubview(webview )
    webview.loadRequest(NSURLRequest(URL:NSURL(字符串:whatsapp:// send?text = Hello%2C%20World!)!))


所有这些解决方案都打开了另一个应用程序 - 我想仍然留在我的应用程序中。



任何想法如何实现这一目标?非常感谢帮助:)

解决方案

其实我做的完全一样,但这个解决方案还需要你实现侧服务器继续支持在AppStore上弹出的新应用程序(无需每次需要/想要在列表中添加/删除新应用程序时更新您的应用程序)



第1名:
您需要决定在其他应用上分享的内容



第二名:您需要找出应用程序使用的URL方案,



instagram的例子 - >instagram:// user?username = your_username



第三:现在这个过程背后的逻辑



让我说我想展示facebook,twitter,slack和instagram,



让我们设置带有相关网址的字典:

  [facebook :facebook:// blablabla,twitter:twitter:// blabla,slack:slack:// blabla,instagram:instagram:// blabla] 

您还需要保留APP的图标(本地或服务器/ firebase /云) - 稍后会在您的滚动视图中显示(horizo​​ntaly collectionview或你决定使用什么)



4rd:你需要检查设备上是否安装了这些应用程序:



所以只需循环你的应用程序阵列/字典(或者你决定保留你的信息并检查这样的可用性:

 让instagramHooks =instagram:// user?username = your_username
let instagramUrl = URL(string:instagramHooks)
if UIApplication.shared.canOpenURL (instagramUrl!作为URL)
{
//应用程序已安装,您可以显示她
}其他{
//应用程序未安装 - >不要在列表中显示
}

之后你只需要把他们的UICollectionView / UIScrollView的图标,当用户点击图标时,你会打开该计划:

  UIApplication.shared.open(instagramUrl! )

关于目标应用程序将如何显示对话框(如UIActivityViewController操作或实际打开应用程序我现在没有),但我相信你可以在这里找到帮助你的人



跳过你理解我的步骤,如果没有您可以与我联系以获得更多解释


I want to be able to have social icons in a scrollView, which when clicked, functions the same way it would if I had clicked on them after presenting a UIActivityViewController. I don't want to present a UIActivityViewController.

I know it shouldn't be possible, but an app called Yodel does this (or something similar) and I want to do the same.

Clicking on the icons in Yodel works exactly the same as it would in a UIActivityViewController, so it seems they have somehow put it inside a container view(?)

Here's a GIF showing it

Using Whatsapp as an example I've tried the following:

  1. Using the Whatsapp API https://www.whatsapp.com/faq/en/iphone/23559013 with URL scheme

        var whatsappURL = NSURL(string: "whatsapp://send?text=Hello%2C%20World!")!
        if UIApplication.sharedApplication().canOpenURL(whatsappURL) {
            UIApplication.sharedApplication().openURL(whatsappURL)
        }
    

  2. Using UIActivityViewController, but I want them all to be in a scrollView as seen in the picture above.

  3. Using a UIWebView to open up the URL Scheme in hopes that it would stay inside the UIWebView.

    var whatsappURL = NSURL(string: "whatsapp://send?text=Hello%2C%20World!")!
    if UIApplication.sharedApplication().canOpenURL(whatsappURL) {
        UIApplication.sharedApplication().openURL(whatsappURL)
    }
    
    self.view.addSubview(webview)
    webview.loadRequest(NSURLRequest(URL: NSURL(string: "whatsapp://send?text=Hello%2C%20World!")!))
    

All of these solutions opens up the other app - I want to still stay in my app.

Any idea how to accomplish this? Help would be greatly appreciated :)

解决方案

Actually I did exactly the same, but this solution need you to also implement side server for continues support for new apps that pops on AppStore (without update your app for everytime you need/want to add/remove new app to/from the list)

1st: You need to decide what are you going to share on other apps

2nd: you need to find out the URL Scheme that apps work with,

example for instagram -> "instagram://user?username=your_username"

3rd: now the logic behind the process

let's say i want to show facebook, twitter, slack and instagram,

let's set dictionary with relevant URLs:

["facebook":"facebook://blablabla", "twitter":"twitter://blabla", "slack":"slack://blabla", "instagram":"instagram://blabla"]

ALSO YOU NEED TO HOLD THE APP's ICONS (locally or server/firebase/cloud) - to display later on your scrollview(horizontaly collectionview or what ever you decide to use)

4rd: you need to check if that apps are installed on the device:

So just loop on your apps array/dictionary (or what ever you decide to hold your info and check for availability like that:

let instagramHooks = "instagram://user?username=your_username"
let instagramUrl = URL(string: instagramHooks)
if UIApplication.shared.canOpenURL(instagramUrl! as URL)
{
 //The app are installed you can show her
 } else {
       //The app doesn't installed -> don't show it on the list
    }

After that you just need to put their icons to UICollectionView / UIScrollView and when user tap on icon you go and open that scheme:

UIApplication.shared.open(instagramUrl!)

About how the target app will show the dialog (like UIActivityViewController action or actually open the app i don't now), but I'm sure you can find here someone that help you with that

Hop you understand my steps, if not you can contact with me for more explanation

这篇关于打开活动而不显示UIActivityViewController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆