launchOptions中的可能键值见UIApplication Class Reference的Launch Options Keys节 。
- 若用户直接启动,lauchOptions内无数据;
- 若由其他应用程序通过openURL:启动,则UIApplicationLaunchOptionsURLKey对应的对象为启动URL(NSURL),UIApplicationLaunchOptionsSourceApplicationKey对应启动的源应用程序的bundle ID (NSString);
- 若由本地通知启动,则UIApplicationLaunchOptionsLocalNotificationKey对应的是为启动应用程序的的本地通知对象(UILocalNotification);
- 若由远程通知启动,则UIApplicationLaunchOptionsRemoteNotificationKey对应的是启动应用程序的的远程通知信息userInfo(NSDictionary);
- 其他key还有UIApplicationLaunchOptionsAnnotationKey,UIApplicationLaunchOptionsLocationKey, UIApplicationLaunchOptionsNewsstandDownloadsKey。
代码区分不同的启动,如点击推送可以做出跳转
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSURL *url = [options objectForKey:UIApplicationLaunchOptionsURLKey]; if(url) { //由其他应用程序通过openURL:启动 } NSString *bundleId = [options objectForKey:UIApplicationLaunchOptionsSourceApplicationKey]; if(bundleId) { //对应启动的源应用程序的bundle ID (NSString) } UILocalNotification * localNotify = [options objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]; if(localNotify) { //点击本地推送进来后 } NSDictionary * userInfo = [options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey]; if(userInfo) { //点击推送进来后 } }