iOS - didRecieveRemoteNotification 在应用程序未运行时无法正常工作 运行

iOS - didRecieveRemoteNotification not working when app is not running

当应用处于 运行 或处于后台时,推送通知正在调用 didReceiveRemoteNotification。 但是如果用户 "kills" 应用程序和我发送推送通知,当用户点击通知时,应用程序不会调用 didReceiveRemoteNotification

这是我的:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)dict{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:dict[@"title"]
                                                message:dict[@"description"]
                                               delegate:self
                                      cancelButtonTitle:@"OK"
                                      otherButtonTitles:nil];

[alert show];

NSLog(@"didReceiveRemoteNotification: %@", dict);}

根据 UIApplicationDelegate 协议参考:

If the app is not running when a remote notification arrives, the method launches the app and provides the appropriate information in the launch options dictionary. The app does not call this method to handle that remote notification. Instead, your implementation of the application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions: method needs to get the remote notification payload data and respond appropriately.

当您的应用程序启动时,applicationDidFinishLaunching 将包含在应用程序终止时收到的任何远程通知的数据。当您的应用程序完成启动时,使用下面的代码。

if ([launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey]) 
{
   [self application:application didReceiveRemoteNotification:launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey]];
}

来源https://developer.apple.com/library/ios/documentation/UIKit/Reference/UIApplicationDelegate_Protocol/#//apple_ref/occ/intfm/UIApplicationDelegate/application:didReceiveRemoteNotification: