0

This is implemented in AppDelegate

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

I have App Link with some parameters that is shared on Facebook. If my app is minimized, clicking link on Facebook opens my app and calling function

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool

like it should happened.

Problem is if my app is terminated (not minimized) clicking link on Facebook opens my app but function is not called so I can't process input params.

I have found something about handling cold start in Facebook documentation but that info is outdated.

Did I miss something to implement or it is Facebook bug?

NFilip
  • 427
  • 4
  • 15
  • 1
    The only way for the Facebook app to open your app on iOS is by calling the openURL method, which should call your app delegate's openURL method, regardless of whether it's a cold start or just minimized. – Ming Li May 14 '15 at 17:48
  • @MingLi, but OpenURL method is not getting called when we we wrote as above in didfinishLaunch Method. it is always called didFinishLaunch method. – user2526811 Aug 25 '15 at 11:21
  • @NFilip Did you get any solution for this? – user2526811 Sep 05 '15 at 07:12
  • Yes, I have done like @Nick Yap said but I forgot to post answer here. – NFilip Sep 06 '15 at 12:33

1 Answers1

3

I was boggling my head about this for a while...

When you open an app link and the app is not currently running, the app launches and first calls application:didFinishLaunchingWithOptions. If you return true in this method, then it will follow by calling application:openURL:sourceApplication:annotation: and passing in the proper parameters. However, if application:didFinishLaunchingWithOptions returns false, then application:openURL:sourceApplication:annotation: is never called.

If you are using the FBSDK, then you will be calling

return FBSDKApplicationDelegate.sharedInstance().application(application,
didFinishLaunchingWithOptions: launchOptions)

at the end of your application:didFinishLaunchingWithOptions. If you look at their documentation, it states that it returns

YES if the url was intended for the Facebook SDK, NO if not.

So, because YOUR applink is not intended for the FBSDK, it is returning false. However, the keys UIApplicationLaunchOptionsURLKey and UIApplicationLaunchOptionsSourceApplicationKey ARE available in your launchOptions. In your application:didFinishLaunchingWithOptions, if you call

if let url = launchOptions?[UIApplicationLaunchOptionsURLKey] as? NSURL,
  sourceApplication = launchOptions?[UIApplicationLaunchOptionsSourceApplicationKey] as? String {      
   self.application(application, openURL: url, sourceApplication: sourceApplication, annotation: nil) 
}

then you can get around it. I'm not sure if you're supposed to be calling the AppDelegate methods manually, but it works for me.

Nick Yap
  • 887
  • 1
  • 10
  • 13