Launch App using URL, but OpenUrl Not Called

后端 未结 8 1372
长发绾君心
长发绾君心 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 00:47

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

提交回复
热议问题