Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle if app is opened from URL in didFinishLaunchingWithOptions method?

When iOS application is opened from some URL AppDelegates's methods are called in such a sequence:

1. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

2. - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url

How to know in didFinishLaunchingWithOptions method if application was opened from URL or not. May be there are some launching options which I miss?

like image 611
B.S. Avatar asked Jul 31 '13 11:07

B.S.


2 Answers

You can inspect launchOptions passed to - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions.

Look for section Launch Options Keys in reference docs, specifically UIApplicationLaunchOptionsURLKey

like image 112
Max Komarychev Avatar answered Nov 01 '22 17:11

Max Komarychev


If your app has been launch from a URL You will find a

UIApplicationLaunchOptionsURLKey 

in the launchOptions Dictionary of - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

On a related note the handleOpenURL: method is deprecated, you should use:

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
like image 30
Eric Genet Avatar answered Nov 01 '22 17:11

Eric Genet