Launch App using URL, but OpenUrl Not Called Launch App using URL, but OpenUrl Not Called objective-c objective-c

Launch App using URL, but OpenUrl Not Called


I agree with Kaloyan, "handleOpenURL" is never called at application launch. So you have to check for URL in "launchOptions" in didFinishLaunchingWithOptions.

HOWEVER

I adopted the same solution as Apple example code for QuickActions (3D Touch). I keep the URL at launch in a variable, and I handle it in applicationDidBecomeActive:.

@interface MyAppDelegate ()@property (nonatomic, strong) NSURL *launchedURL;@end@implementation MyAppDelegate- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{    self.launchedURL = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];    ...}- (void)applicationDidBecomeActive:(UIApplication *)application{    if (self.launchedURL) {        [self openLink:self.launchedURL];        self.launchedURL = nil;    }}- (BOOL)  application:(UIApplication *)application          openURL:(NSURL *)urlsourceApplication:(NSString *)sourceApplication       annotation:(id)annotation{    NSURL *openUrl = url;    if (!openUrl)    {        return NO;    }    return [self openLink:openUrl];}- (BOOL)openLink:(NSURL *)urlLink{    ...}@end


I believe there is a better answer now as,

  • application:handleOpenURL:
  • application:openURL:sourceApplication:annotation:Both are deprecated in ios 9. Apple suggestion is:

Use application:openURL:options: instead.

application:openURL:options: has different behaviour than the old ones, as it will be executed in case the app was in background or will launch.

So, you need to handle the URL opening within it only. like below:

- (BOOL)application:(UIApplication *)app        openURL:(NSURL *)url        options:(NSDictionary<NSString *,id> *)options {    // Check the calling application Bundle ID    if ([[url scheme] isEqualToString:@"yuvitime"])    {        NSLog(@"URL scheme:%@", [url scheme]);        NSString * yuvitimeRequestValue = [url query];        NSDictionary * userInfor = [[NSDictionary alloc]initWithObjectsAndKeys:yuvitimeRequestValue, @"YuvitimeRequest", nil];        NSNotificationCenter * notificationCentre = [NSNotificationCenter defaultCenter];        [notificationCentre postNotificationName:@"URLSCHEMEACTIVATEDNOTIFICATION" object:self userInfo:userInfor];        return YES;    }    else        return NO;}


Hi when the app is not launched before, the method "handleOpenURL" is never called. You have to check "launchOptions" in didFinishLaunchingWithOptions for object with key "UIApplicationLaunchOptionsURLKey"

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {NSURL *url = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];//call function to handle the url like in handleURL, but do not call handleURL directly}