0

When does a custom URL get populated in launchOptions in the AppDelegate.m file? I've loaded my apps' custom URL in Safari and UIApplicationLaunchOptionsURLKey is not populated.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{    

    NSLog(@"app launch options");
    NSLog([launchOptions valueForKey:UIApplicationLaunchOptionsURLKey]);
}
locoboy
  • 38,002
  • 70
  • 184
  • 260

2 Answers2

2

UIApplicationLaunchOptionsURLKey gets populated when you try to open the app by means of:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"yourapp://"]];

...and yourapp is not running.

Then (BOOL)application:(UIApplication *):didFinishLaunchingWithOptions:(NSDictionary *) will get executed and NSDictionary will get populated with two key-values UIApplicationLaunchOptionsURLKeyand UIApplicationLaunchOptionsSourceApplicationKey

agy
  • 2,804
  • 2
  • 15
  • 22
  • What's the best way to see my NSLog if I terminate my app and then launch it again in xcode? Also, does the launchOptions not get populated when it comes from safari? – locoboy Jul 28 '15 at 07:15
  • If your are running the app in a real device. Window->Devices and there you can see the console log of your device. – agy Jul 28 '15 at 07:19
  • http://stackoverflow.com/questions/10165641/how-can-i-get-the-console-logs-from-the-ios-simulator You can also use Console.app from your mac and open ~/Library/Logs/CoreSimulator//system.log – agy Jul 28 '15 at 07:24
2

The main entry point for any C derived program is a function called main, and in ObjC it's called int main. This kicks of a series of events that ultimately calls the applicationDidFinishLaunchingWithOptions: method that ultimately leads to the user getting to see the first "screen" you want them to see.

2 things will happen after applicationDidFinishLaunchingWithOptions: in the next series of events.

  1. If there is a populated URL key it will use that URL key and call applicationDidBecomeActive:.

  2. If there is not a URL key set it will then call application: openURL: sourceURL: annotation which is where you would set it.

That does leave an issue of how it is populated for the initial call in applicationDidFinishLaunchingWithOptions:. I believe you can set this in the info.list file.

Brandon A
  • 21
  • 1