最近打包上線app被拒,信息如下:
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.
由于本人之前也沒(méi)遇到過(guò)這類(lèi)的被拒經(jīng)歷,反復(fù)檢查項(xiàng)目入口類(lèi)的方法,測(cè)試了大概15個(gè)版本,挨個(gè)注釋,再使用TestFilght 預(yù)先測(cè)試版本。最終發(fā)現(xiàn)問(wèn)題,用testflight打開(kāi)app的時(shí)候直接閃退,先讓我們來(lái)分析一下入口類(lèi)的方法。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions;
當(dāng)應(yīng)用程序啟動(dòng)時(shí)執(zhí)行,應(yīng)用程序啟動(dòng)入口。只在應(yīng)用程序啟動(dòng)時(shí)執(zhí)行一次。application參數(shù)用來(lái)獲取應(yīng)用程序的狀態(tài)、變量等,值得注意的是字典參數(shù):(NSDictionary *)launchOptions,該參數(shù)存儲(chǔ)程序啟動(dòng)的原因。
1.若用戶直接啟動(dòng),lauchOptions內(nèi)無(wú)數(shù)據(jù);
2.若由其他應(yīng)用程序通過(guò)openURL:啟動(dòng),則UIApplicationLaunchOptionsURLKey對(duì)應(yīng)的對(duì)象為啟動(dòng)URL(NSURL),UIApplicationLaunchOptionsSourceApplicationKey對(duì)應(yīng)啟動(dòng)的源應(yīng)用程序的bundle ID (NSString);
3.若由本地通知啟動(dòng),則UIApplicationLaunchOptionsLocalNotificationKey對(duì)應(yīng)的是為啟動(dòng)應(yīng)用程序的的本地通知對(duì)象(UILocalNotification);
4.若由遠(yuǎn)程通知啟動(dòng),則UIApplicationLaunchOptionsRemoteNotificationKey對(duì)應(yīng)的是啟動(dòng)應(yīng)用程序的的遠(yuǎn)程通知信息userInfo(NSDictionary);
其他key還有UIApplicationLaunchOptionsAnnotationKey,UIApplicationLaunchOptionsLocationKey,UIApplicationLaunchOptionsNewsstandDownloadsKey。
如果要在啟動(dòng)時(shí),做出一些區(qū)分,那就需要在下面的代碼做處理。 比如:應(yīng)用可以被某個(gè)其它應(yīng)用調(diào)起(作為該應(yīng)用的子應(yīng)用),要實(shí)現(xiàn)單點(diǎn)登錄,那就需要在啟動(dòng)代碼的地方做出合理的驗(yàn)證,并跳過(guò)登錄。
- (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){
}
}
最后大家應(yīng)該明白為什么 會(huì)閃退了把。沒(méi)錯(cuò),就是因?yàn)楫?dāng)你用第三方打開(kāi)app的時(shí)候,應(yīng)用程序通過(guò)openURL:啟動(dòng) didFinishLaunchingWithOptions方法。
