Launch App using URL, but OpenUrl Not Called

后端 未结 8 1381
长发绾君心
长发绾君心 2020-12-31 00:43

I have implemented a URL Scheme and use it to pass data to my app by calling method. The entire code is shown as below

- (BOOL)application:(UIApplication *)a         


        
8条回答
  •  悲&欢浪女
    2020-12-31 01:11

    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 *)url
    sourceApplication:(NSString *)sourceApplication
           annotation:(id)annotation
    {
        NSURL *openUrl = url;
    
        if (!openUrl)
        {
            return NO;
        }
        return [self openLink:openUrl];
    }
    
    - (BOOL)openLink:(NSURL *)urlLink
    {
        ...
    }
    
    @end
    

提交回复
热议问题