简体   繁体   中英

App crashes when didFinishLaunchingWithOptions is called

I have an the app when notification is fired i get a notification bar when the app is in background ,when i tap on that bar it navigates into tableview of the notification set . When i quit the app from background i am receiving notification but when tap on the notification bar the app is getting crashed since its not getting indexpath of the tableview.

When the app is quit in background and reloading the app should enter didfinishlaunching.

In appDidFinishLaunching i am calling the method which navigates into 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];

}

When you quit the app and your app starts again, your viewController is not yet set up. When launching from a notification, you need to check if you are resuming from the background, or launching normally.

Look at applicationWillEnterForeground and applicationDidBecomeActive in the UIApplicationDelegate protocol reference for how to handle resuming your app from various states. Also see: http://developer.apple.com/library/ios/#documentation/iPhone/Conceptual/iPhoneOSProgrammingGuide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW3

我能够解决问题..由于加载错误的xib文件而发生崩溃。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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