Launch App using URL, but OpenUrl Not Called

后端 未结 8 1374
长发绾君心
长发绾君心 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
    
    0 讨论(0)
  • 2020-12-31 01:12

    Swift 2.x

    func application(app: UIApplication, openURL url: NSURL, options: [String : AnyObject]) -> Bool {
    
            if (url.scheme == "yuvitime") {
                print("URL scheme:\(url.scheme)")
                let yuvitimeRequestValue = url.query!
                let userInfor = [
                    "YuvitimeRequest" : yuvitimeRequestValue
                ]
    
                let notificationCentre = NSNotificationCenter.defaultCenter()
                notificationCentre.postNotificationName("URLSCHEMEACTIVATEDNOTIFICATION", object: self, userInfo: userInfor)
                return true
            }
            else {
                return false
            }
    
        }
    
    0 讨论(0)
提交回复
热议问题