Launch App using URL, but OpenUrl Not Called Launch App using URL, but OpenUrl Not Called ios ios

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 landed up with the same issue for an app on iOS 13. Even with the proper implementation of - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey, id> *)options method, it never got invoked.

From iOS13, the SceneDelegates get invoked instead of the AppDelegate method. Once I implemented the

- (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts

on the scene delegate, it would work if the app was already in memory. However, for a cold start, I had to implement the call back

-(void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions

as well.
While implementing

-(void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)connectionOptions

please remember to handle cases when the app is not launched from an URL.

Here is an useful reference: https://forums.developer.apple.com/thread/124132


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;}


matomo