iosswiftdeep-linkingfbsdkfbsdksharekit

Unable to post deep link to Facebook via iOS application


I am trying to use the FBSDK, specifically FBSDKShareKit to let users post a deep link to their wall from my app. I have my App set up with Facebook Developers (I know this isn't the issue because my app users sign in with Facebook with no problem) and have a scheme suffix associated with the app. enter image description here

My application's info.plist has the same suffix set. I know this works because when opening a URL with this suffix from Safari, it navigates to my application. enter image description here

When opening a URL, my app delegate checks if the URL host matches a certain string, if it does, I then check if the URL path matches a certain string. If both of these match, then I parse the parameters passed from the URL, create a custom object (in this case, an event), instantiate a view controller, and populate that view controller with the custom object's properties.

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {


    if url.host != "www.mywebsite.app" {
        return false
    } else if url.path == "/sharedEvent" {
        if let parameters = url.queryParameters {

            //Get params from url
            let name = parameters["name"]!
            let description = parameters["description"]!
            let lat = parameters["lat"]!.CGFloatValue()
            let lng = parameters["lng"]!.CGFloatValue()
            let startTime = Int(parameters["startTime"]!)!
            let endTime = Int(parameters["endTime"]!)!
            let categories = parameters["categories"]!
            let priority = Int(parameters["priority"]!)!
            let id = parameters["id"]!
            let userId = parameters["userId"]!
            let userName = parameters["userName"]!
            let userEmail = parameters["userEmail"]!
            let photoURLs = parameters["photoURLs"]!
            let isVerified = Int(parameters["isVerified"]!)


            //Create event from parameters
            let sharedEvent = Event(name: name, description: description, lat: lat, long: lng, startTime: Date(timeIntervalSince1970: Double(startTime)), endTime: Date(timeIntervalSince1970: Double(endTime)), categories: [categories], priority: priority, id: id, userId: userId, userName: userName, userEmail: userEmail, photoURLs: [photoURLs], isVerified: isVerified!)

            //Instantiate eventVC
            let storyboard = UIStoryboard(name: "Main", bundle: .main)
            let eventVC = storyboard.instantiateViewController(withIdentifier: "EventViewController") as! EventViewController
            eventVC.event = sharedEvent
            eventVC.userId = userId
            eventVC.userEmail = userEmail
            eventVC.userName = userName
            DispatchQueue.main.async {
                self.window!.rootViewController!.presentedViewController?.present(eventVC, animated: true, completion: nil)
            }


        }
        return true
    }

This code works as I've tested it by opening a URL from another app with some parameters, and the respective view controller is presented upon the app opening. A URL might look something like this:

fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg@gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1

My issue lies with actually presenting the deep link via Facebook. I've tried two approaches:

  1. Using FBSDKShareKit's FBSDKShareButton by setting the button's shareContent to a FBSDKShareLinkContent with a content url equal to the one shown above. Doing this results in a greyed out, i.e. disabled, FBSDKShareButton. Changing the content's URL to something like "www.google.com" enables the button, meaning that Facebook doesn't like my URL for some reason.

    let button = FBSDKShareButton()
    let shareContent = FBSDKShareLinkContent()
    content.contentURL = URL(string: "fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg@gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1")
    button.shareContent = content
    
  2. Using iOS's Social framework to instantiate an SLComposeViewController, setting said view controller's URL to the same one above, and presenting the view controller. Upon posting through Facebook, I'm prompted with the error message "There was a problem sharing your link." Again, when replacing the URL in question with "www.google.com," the post goes through successfully, indicating, again, that Facebook doesn't like the deep link I'm providing for some reason.

    @IBAction func shareButtonPressed(_ sender: Any) {
    
        let vc = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
        vc?.add(loadedImages.first?.image)
    
        vc!.add(URL(string: shareURL))
        for photo in self.loadedImages {
            vc!.add(photo.image!)
        }
        present(vc!, animated: true, completion: nil)
    }
    

The SLComposeViewController presenting the link, which Facebook clearly doesn't like

The error I'm presented with when trying to post my deep link on Facebook via SLComposeViewController

So, in conclusion, I believe that the issue here lies with the fact that Facebook won't allow me to post:

fb1068346896678533://www.hootevents.app/sharedEvent?name=Some%20Name&description=Some%20description&lat=38.7016&lng=-90.447&startTime=1548466210&endTime=1551058140&categories=lhw9bs31nr2twlx&priority=1&id=15510581401548012896PfZLZCzDUh&userId=f5qLpyu4XNWa4eJI17sBi71bIw23&userName=David%20Chopin&userEmail=chopindavidg@gmail.com&photoURLs=https://upload.wikimedia.org/wikipedia/commons/thumb/2/2f/Google_2015_logo.svg/1200px-Google_2015_logo.svg.png&isVerified=1

on behalf of users. If this is the case, how am I supposed to format my deep link so that users can post it to their wall from my app, effectively sharing events with their Facebook friends and, ideally, driving more traffic to my app?


Solution

  • It seems all I had to do was wait a while (I guess it can take up to 48 hours for the link to start working?).

    Note that the Facebook app does not allow users to navigate to another app via universal/deep linking. Their in-app browser is designed to not allow this to happen. There are some workaround, most notably Branch.io, which allows users to get use out of their universal links through Facebook.