gpt4 book ai didi

iphone - 应用程序未运行时处理远程通知时崩溃

转载 作者:太空狗 更新时间:2023-10-30 03:30:31 25 4
gpt4 key购买 nike

我收到远程通知并根据通知类型更改导航 Controller 的 View Controller 。

当应用程序在前台时,或者当应用程序在后台但未完全关闭(从多任务栏)时,一切正常。

但是,当应用程序关闭并收到远程通知时,它会在打开后立即崩溃。我设置 ViewController 的方式有问题吗?

这是一些代码。

- (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];
}

最佳答案

我已经解决了这个问题,正如我所想的那样,它与 View Controller 无关。

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

之前

UILocalNotification *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

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

应该是

NSDictionary *remoteNotif = [launchOptions objectForKey: UIApplicationLaunchOptionsRemoteNotificationKey];

[self handleRemoteNotification:application userInfo:remoteNotif];

关于iphone - 应用程序未运行时处理远程通知时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4295122/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com