更新时间:2022-10-16 17:15:30
我得到这个解决了,它有没有关系视图控制器,因为我以为。
问题是以下行。我在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];