Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open activity without showing 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

enter image description here

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 :)

like image 617
Morten Stulen Avatar asked Oct 16 '16 19:10

Morten Stulen


1 Answers

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

like image 172
Dekel Maman Avatar answered Nov 07 '22 17:11

Dekel Maman