Pra*_*nna 8 iphone objective-c push-notification apple-push-notifications
我收到远程通知,并根据通知类型更改导航控制器的视图控制器.
当应用程序在前台,或者应用程序在后台但未完全关闭时(从多任务栏),一切正常.
但是,当应用程序关闭并收到远程通知时,它会在打开时立即崩溃.我在设置ViewControllers的方式上做错了吗?
这是一些代码.
- (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];
}
Run Code Online (Sandbox Code Playgroud)
Pra*_*nna 15
我解决了这个问题,它与视图控制器无关,正如我想的那样.
问题在于以下几行.我发送的是remoteNotif.userInfo而不是remoteNotif本身.此外,remoteNotif显然不是UILocalNotification类型.它是一个NSDictionary对象.
之前
UILocalNotification *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
[self handleRemoteNotification:application userInfo:remoteNotif.userInfo];
Run Code Online (Sandbox Code Playgroud)
应该
NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];
[self handleRemoteNotification:application userInfo:remoteNotif];
Run Code Online (Sandbox Code Playgroud)
如果您关闭从xcode调试模式开始的应用程序,并且当应用程序以推送通知(已关闭的应用程序)启动时,如果您的手机连接到Mac(仍然是您的手机处于调试模式与xcode),它将崩溃.用拔掉的电话测试这个senario.
| 归档时间: |
|
| 查看次数: |
10132 次 |
| 最近记录: |