繁体   English   中英

调用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协议参考中查看applicationWillEnterForegroundapplicationDidBecomeActive ,以了解如何处理从各种状态恢复应用程序的问题。 另请参阅: 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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM