Facebook App links does not redirect if app is not installed

时间:2015-06-15 15:17:56

标签: ios facebook swift applinks

I am trying to share a picture on Facebook through an app I am making.

If the user has the app installed on his iPhone I want him to open the picture link with the app instead of the web browser. I am using app links for that purpose (http://applinks.org/documentation/)

Everything works fine. But if the user has not the app installed, he cannot open the link with the browser. I think the error comes from my webParam (see below).

Any ideas ?

var iosParam = "[{\"url\" : \"\(urlScheme)\",\"app_name\" : \"AppName\"}]"
var webParam = "{\"url\" : \"https://www.facebook.com/myAppName\"}"

var param = [
   "name" : "app link host",
   "ios" : iosParam,
   "web": webParam,
   "access_token" : token
]

var fbRequest = FBSDKGraphRequest(graphPath: "/app/app_link_hosts", parameters: parameters, HTTPMethod: "POST")
        fbRequest.startWithCompletionHandler { (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
            if error == nil{

                let id:String = result["id"] as! String
                let token:String = parameters["access_token"]! as! String
                var param:[String: String] = ["access_token": token]

                // get the canonical URL from the app link host ID
                var requestCanonicalURL = FBSDKGraphRequest(graphPath: "/\(id)", parameters: param, HTTPMethod: "GET")
                requestCanonicalURL.startWithCompletionHandler({ (connection: FBSDKGraphRequestConnection!, result: AnyObject!, error: NSError!) -> Void in

                    if error == nil {
                        self.share(result["canonical_url"] as! String)
                    }else{
                        NSLog("Error: %@", error)
                    }
                })
            }else{
                NSLog("Error: %@", error)

            }
        }

And here is some of the code of the share() function:

var properties = [
        "og:type": "appType:appType",
        "og:title": "What do you think?",
        "og:description": "This is a description",
        "og:url": canonicalURL,
        "og:image": [photo]
    ]
var object = FBSDKShareOpenGraphObject(properties: properties as [NSObject : AnyObject])

var action = FBSDKShareOpenGraphAction()
action.actionType = "appType:share"
action.setObject(object, forKey: "appObject:appObject")

var content = FBSDKShareOpenGraphContent()
content.action = action
content.previewPropertyName = "previewPropertyName:previewPropertyName"

FBSDKShareDialog.showFromViewController(self, withContent: content, delegate: nil)

0 个答案:

没有答案