推送通知在应用程序运行时或在后台时调用 didReceiveRemoteNotification
。
但是,如果用户“杀死”应用程序并且我发送推送通知,当用户点击通知时,应用程序不会调用 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 协议(protocol)引用:
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]];
}
关于iOS - 当应用程序未运行时 didRecieveRemoteNotification 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29524111/