程序启动之后总会调用ddidFinishLaunchingWithOptions方法,其中launchOptions参数是NSDictionary类型的对象,里面存储的是程序启动的原因。
一般分为以下几种原因:
1.用户直接启动,则launchOptions无数据
2.用户由其他应用程序通过openURL启动
则UIApplicationLaunchOptionsURLKey对应的对象为启动URL
UIApplicationLaunchOptionsSourceApplicationKey对应启动的源应用程序的bundle ID
3.用户由本地通知启动
则UIApplicationLaunchOptionsLocalNotificationKey对应的是为启动应用程序的本地推送对象UILocalNotification
4.用户由远程推送通知启动
则UIApplicationLaunchOptionsRemoteNotificationKey对应的是为启动应用程序的远程通知信息
5.其他的还有UIApplicationLaunchOptionsAnnotationKey, UIApplicationLaunchOptionsLocationKey,UIApplicationLaunchOptionsNewsstandDownloadsKey等
didFinishLaunchingWithOptions:launchOptions中代码如下:
if (!launchOptions) {
//用户直接启动
}else {
//用户由其他应用程序通过openURL启动
NSURL * openURL = [launchOptions objectForKey:UIApplicationLaunchOptionsURLKey];
if (url) {
NSLog(@"启动 openURL = %@", openURL);
}
//用户由本地通知启动
UILocalNotification *localNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if(localNotification) {
NSLog(@"本地通知启动 localNotification = %@",localNotification);
}
//用户由远程推送通知启动
NSDictionary *remoteNotificationDic = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(remoteNotificationDic) {
NSLog(@"远程推送通知启动 remoteNotificationDic = %@",remoteNotificationDic);
}
}
注:文章参考于网络,如有雷同敬请谅解,若有问题可私信联系删除
宝宝是个踏实的搬运工