我从服务器发送推送通知,如果应用程序在后台运行,通知到达并点击它调用 didReceiveRemoteNotification()。
但是当我杀死我的应用程序时(双击主页按钮后向上滑动应用程序,通知到达但点击通知只会将屏幕定向到应用程序主页。我已经在 didFinishLaunchingWithOptions:launchOptions() 中编码,如下所示。
if (launchOptions != nil)
{
NSDictionary* dictionary = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey];
if (dictionary != nil)
{
NSLog(@"Launched from push notification: %@", dictionary);
NSString *strVendId=[dictionary valueForKeyPath:@"payload.vendor_id"];
UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UINavigationController *navController = (UINavigationController *)self.window.rootViewController;
VenderDetailController *vDetail=[mainstoryboard instantiateViewControllerWithIdentifier:@"venDetail"];
vDetail.strVendorId=strVendId;
[navController pushViewController:vDetail animated:YES];
}
}
当应用程序被杀死时,我无法调试它。也许我没有得到我无法分辨的字典。我什至尝试删除 launchOption nil 条件,仍然没有帮助。
我正在使用 Objective-C ,这个问题快把我逼疯了。
最佳答案
首先检查设备日志中的日志以确认Dictionary是否为nil。用于在应用程序终止时检查日志。转到窗口 -> 设备,然后选择您的设备,然后点击左下角的箭头图标,如下图所示。即使您没有从 Xcode 运行应用程序,您也可以看到所有日志:
记录你得到的字典,这将有助于调试。
关于ios - 为什么我使用 launchOption 字典 nil 获得 Apple Push Notification?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37270699/