As the sequence of events is slightly different depending on which of these two scenarios is in progress, I would like to be able to tell the difference. Any suggestions?
You should not use handleOpenURL
since it's deprecated. Instead, use application:openURL:sourceApplication:annotation:
(available since iOS 4.2).
Apple's documentation gives the answer to your question here regarding application:openURL:sourceApplication:annotation
:
If your app had to be launched to open the URL, the app calls the application:willFinishLaunchingWithOptions: and application:didFinishLaunchingWithOptions: methods first, followed by this method. The return values of those methods can be used to prevent this method from being called. (If the application is already running, only this method is called.)
Did you tried this method in AppDelegate?
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
NSLog(@"Launched with URL: %@", url.absoluteString);
[[NSNotificationCenter defaultCenter] postNotificationName:NOTIFICATION_APP_OPENED_FROM_LINK object:[userDict objectAtIndex:0]];
return YES;
}
In my case i had to create the navigation flow again if the app is launched when the app is running at background, but if the app is launched for the first time there was no need for that. My implementation was:
- (BOOL) application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.appIsLaunchedFromZeroToOpenURL = false;
//some other code
NSURL *applicationOpenURL = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
if (applicationOpenURL) {
self.appIsLaunchedFromZeroToOpenURL = true;
}
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
if (self.appIsLaunchedFromZeroToOpenURL == false) {
//app should reload the navigation then navigate to url if the app is not launched for the first time
[self createNavigationFromZero];
}
[self openURL:url];//navigate to the url
self.appIsLaunchedFromZeroToOpenURL = false;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With