处理远程通知时发生崩溃时,应用程序不运行 [英] Crash when handling remote notification when app not running

查看:134
本文介绍了处理远程通知时发生崩溃时,应用程序不运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到远程通知,并根据通知,变更导航控制器的视图控制器的类型。

这一切工作正常时,应用程序是在前台,或当应用程序在后台,但没有完全关闭(从多任务栏)。

不过,当应用程序被关闭,并接受它,一旦它打开就死机远程通知。我做错了什么与我建立ViewControllers的方式吗?

下面是一些code。

   - (BOOL)应用:(*的UIApplication)的应用didFinishLaunchingWithOptions:(NSDictionary的
*){launchOptions
   //需要推到屏幕导航控制器         UILocalNotification * remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];    //接受推送通知的应用程序时未打开
    如果(remoteNotif){
        [个体经营handleRemoteNotification:应用程序用户信息:remoteNotif.userInfo];
        返回YES;
    }    [窗口addSubview:navigationController.view];
    [窗口makeKeyAndVisible]    返回YES;
} - (无效)handleRemoteNotification:(UIApplication的*)的应用程序用户信息:(NSDictionary的*){用户信息
    application.applicationIconBadgeNumber = 0;NSMutableArray里* viewControllers = [NSMutableArray的阵列]
    [viewControllers ADDOBJECT:driverWaitViewController];
    [viewControllers ADDOBJECT:newJobsViewController];    【navigationController setViewControllers:viewControllers];
}


解决方案

我得到这个解决了,它有没有关系视图控制器,因为我以为。

问题是以下行。我在remoteNotif.userInfo发送,而不是remoteNotif本身。此外,remoteNotif显然不是类型UILocalNotification的。这是一个的NSDictionary对象。

之前

  UILocalNotification * remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];[个体经营handleRemoteNotification:应用程序用户信息:remoteNotif.userInfo];

 的NSDictionary * remoteNotif = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];[个体经营handleRemoteNotification:应用程序用户信息:remoteNotif];

I receive a remote notification and according to the type of notification, change navigation controller's view controllers.

It all works fine when the app is in the foreground, or when the app is in the background but not completely closed (from multi-tasking bar).

But, when the app is closed, and receives a remote notification it crashes as soon as it opens. Am I doing wrong with the way I am setting up the ViewControllers?

Here's some code.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary
*)launchOptions {
   // Push required screens into navigation controller

         UILocalNotification *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

    //Accept push notification when app is not open
    if (remoteNotif) {      
        [self handleRemoteNotification:application userInfo:remoteNotif.userInfo];
        return YES;
    }

    [window addSubview:navigationController.view];
    [window makeKeyAndVisible];

    return YES;
}

-(void) handleRemoteNotification:(UIApplication *)application userInfo:(NSDictionary *)userInfo {
    application.applicationIconBadgeNumber = 0;

NSMutableArray *viewControllers = [NSMutableArray array];
    [viewControllers addObject:driverWaitViewController];
    [viewControllers addObject:newJobsViewController];

    [navigationController setViewControllers:viewControllers];
}

解决方案

I got this resolved, and it has nothing to do with view controllers, as I thought.

The issue was in the following lines. I was sending in remoteNotif.userInfo rather than remoteNotif itself. Also, remoteNotif is obviously not of type UILocalNotification. It is a NSDictionary object.

Before

UILocalNotification *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

[self handleRemoteNotification:application userInfo:remoteNotif.userInfo];

Should be

NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

[self handleRemoteNotification:application userInfo:remoteNotif];

这篇关于处理远程通知时发生崩溃时,应用程序不运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆