ios - 为什么我使用 launchOption 字典 nil 获得 Apple Push Notification?

标签 ios objective-c apple-push-notifications

我从服务器发送推送通知,如果应用程序在后台运行,通知到达并点击它调用 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 运行应用程序,您也可以看到所有日志:enter image description here enter image description here

记录你得到的字典,这将有助于调试。

关于ios - 为什么我使用 launchOption 字典 nil 获得 Apple Push Notification?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37270699/

相关文章:

ios - Instant AR 框架 Apple Mach-O 链接器错误

objective-c - Command/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-g++-4.2 失败,退出代码为 1

iphone - iOS GameCenter 匹配器不工作

iOS VoIP 推送通知在 1-2 秒后自动停止

Java TLS 套接字 : No trusted certificate found

iphone - Apple 推送通知服务空闲超时

ios - Testflight 不再显示 "Update Profile"选项

iOS 中的 c++ try/catch 无知

ios - 无法更改翻转的 UIImage 图像 Swift 2 iOS 的 tintColor

objective-c - 在 iOS 中创建网络处理程序类时选择什么父类(super class)