![](/img/trans.png)
[英]Iphone app crashes before didFinishLaunchingWithOptions
[英]App crashes when didFinishLaunchingWithOptions is called
觸發通知時,我有一個應用程序。當應用程序處於后台時,我會收到一個通知欄,當我點擊該欄時,它會導航到通知集的tableview中。 當我從后台退出應用程序時,我會收到通知,但是在通知欄上點擊時,應用程序將崩潰,因為它沒有獲取tableview的indexpath。
當應用在后台退出並重新加載時,應進入didfinishlaunching。
在appDidFinishLaunching中,我正在調用導航到tableview的方法
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[PPViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil] ;
UILocalNotification *notification = [launchOptions objectForKey: UIApplicationLaunchOptionsLocalNotificationKey];
if (notification)
{
int remedyID = [[notification.userInfo objectForKey:kRemindMeNotificationRemedyIDKey] intValue];
NSDictionary *reminderDetails =[NSDictionary dictionaryWithObjectsAndKeys:notification.userInfo,@"kRemindMeNotificationDataKey",[NSNumber numberWithInt:remedyID],kRemindMeNotificationRemedyIDKey,nil];
[_viewController goToReminder:reminderDetails showNotification:YES];
}
[application setStatusBarStyle:UIStatusBarStyleBlackTranslucent];
self.viewController = [[PPViewController alloc] initWithNibName:@"PPViewController" bundle:nil];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
**This is the code which navigates into tableview in another viewcontroller**
- (void)goToReminder:(NSMutableDictionary *)reminderDictionary showNotification:(BOOL)shouldShowNotification
{
NSIndexPath *selectedSymptIP = [NSIndexPath indexPathForRow:selectedSymptomIndex inSection:keyIndexNumber];
[self tableView:symptomsTableView didSelectRowAtIndexPath:selectedSymptIP];
}
當您退出應用程序並且應用程序再次啟動時,您的viewController
尚未設置。 從通知啟動時,需要檢查是從后台恢復還是正常啟動。
在UIApplicationDelegate
協議參考中查看applicationWillEnterForeground
和applicationDidBecomeActive
,以了解如何處理從各種狀態恢復應用程序的問題。 另請參閱: http : //developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW3
我能夠解決問題..由於加載錯誤的xib文件而發生崩潰。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.