0

I need to push a viewcontroller when open

- (BOOL)application:(UIApplication *)application
        openURL:(NSURL *)url
        options:(nonnull NSDictionary<NSString *,id> *)options

method is called.

It is working fine when app is in background. But when I have killed the app and the link is clicked, it is not getting pushed. I have a tab bar controller setup in didFinishLaunch method. Will didFinish be called after openURL ?

krishnanunni
  • 510
  • 7
  • 16

2 Answers2

0

If your application is not running, you will be called to application:didFinishLaunchingWithOptions: method with a URL Launch Option Key.

To handle it, check for UIApplicationLaunchOptionsURLKey key in the launch options and extract the URL:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    if (launchOptions[UIApplicationLaunchOptionsURLKey] != nil) {
        // Opened from an URL
    }
}
redent84
  • 18,901
  • 4
  • 62
  • 85
0

I got it. It was because, appdelegate didFinishLaunchmethod is called when app is launched by applink. I am using FBSDK and returning

return [[FBSDKApplicationDelegate sharedInstance] application:application didFinishLaunchingWithOptions:launchOptions];

This will return false in case of my custom scheme. So I explicitly calls this, by checking my URL scheme.

if ([launchURL.scheme isEqualToString:@"urlScheme"]) {
[self application:application openURL:launchURL sourceApplication:sourceApplication annotation:@""]; }

Putting the above code before returning didFinishLaunch solved my issue.

krishnanunni
  • 510
  • 7
  • 16