錯誤提示
We were unable to review your app as it crashed on launch. We have attached detailed crash logs to help troubleshoot this issue.
Next Steps
To resolve this issue, please revise your too and test it on a device to ensure it will launch without crashing.
找到突破口
測試半天,最后使用TESTFILGHT 預先測試版本。最終發現問題,用TESTFLIGHT打開APP的時候直接閃退.
分析原因
– (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
當應用程序啟動時執行,應用程序啟動入口。只在應用程序啟動時執行一次。application參數用來獲取應用程序的狀態、變量等,值得注意的是字典參數:(NSDictionary *)launchOptions,該參數存儲程序啟動的原因.
- 若用戶直接啟動,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){
}
NSString *bundleId = [options objectForKey:UIApplicationLaunchOptionsSourceApplicationKey];
if(bundleId){
}
UILocalNotification * localNotify = [options objectForKey:UIApplicationLaunchOptionsLocalNotificationKey];
if(localNotify){
}
NSDictionary * userInfo = [options objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
if(userInfo){
}
}
原因: 當你用第三方打開APP的時候,應用程序通過OPENURL:啟動 didFinishLaunchingWithOptions方法。