当app被关闭(没有在后台运行)并且手机接收到APNS时,didReceiveRemoteNotification
就不会被调用。
如果应用程序没有在手机的后台运行,就会收到an消息,点击横幅或弹出通知会打开应用程序,但不会调用didReceiveRemoteNotification
委托。
谢谢。
发布于 2014-05-29 06:16:26
只有在您使用应用程序时(当应用程序正在运行时)才会调用didReceiveRemoteNotification,如果您希望在用户单击横幅通知时执行一些专门化操作,则在应用程序的-(BOOL)application:application didFinishLaunchingWithOptions:launchOptions中检查它是否经过通知
// Handle notification when app is quit
NSDictionary *notification = [launchOptions objectForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
if (notification != nil) {
[self handleNotificationsForApplication:application notification:notification];
}
并影响方法handleNotificationsForApplication:application通知:Notification
- (void)handleNotificationsForApplication:(UIApplication *)application notification:(NSDictionary *)userInfo {
NSDictionary *data = [[userInfo objectForKey:@"aps"] objectForKey:@"data"];
NSString *type = [data objectForKey:@"type"];
if ([type isEqualToString:@"app_update"]) {
// Show alert to do the update
}
else if ([type isEqualToString:@"new_chat"]) {
imageData = data;
if (application.applicationState != UIApplicationStateActive) {
// Open chat view
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:APP_NAME
message:[[userInfo valueForKey:@"aps"] valueForKey:@"alert"]
delegate:self
cancelButtonTitle:@"OK"
otherButtonTitles:nil, nil];
[alert setTag:2];
[alert show];
}
}
}
https://stackoverflow.com/questions/23926732
复制相似问题