iOS: 推送通知不显示字典信息 iOS 10
iOS: Push notification not showing dictionary info in iOS 10
我正在 XCode 8 Beta,iOS 10 版本中处理推送通知。我在设备上收到了推送通知。当我点击通知时,它触发了 UNUserNotificationCenterDelegate 的委托,应用程序被打开,但它没有在用户信息中显示任何响应。我是否需要更改参数以在服务器端发送 iOS 10 中的推送。下面是我的代码。
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:settings];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!error) {
NSLog(@"request authorization succeeded!");
}
}];
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSLog(@"Notification is triggered");
completionHandler(UNNotificationPresentationOptionAlert);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
NSLog(@"Tapped in notification");
NSLog(@"%@",response.notification);
NSString *actionIdentifier = response.actionIdentifier;
if ([actionIdentifier isEqualToString:@"com.apple.UNNotificationDefaultActionIdentifier"] ||
[actionIdentifier isEqualToString:@"com.apple.UNNotificationDismissActionIdentifier"]) {
return;
}
}
在iOS9,
aps = {
alert = "Multi extra param push.";
badge = 0;
sound = default;
};
t = I;
url = "http://www.google.com";
并在 iOS 10
alert = "Multi extra param push.";
badge = 0;
sound = default;
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSLog(@"%@", notification.request.content.userInfo);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)())completionHandler {
NSLog(@"%@", response.notification.request.content.userInfo);
}
我正在 XCode 8 Beta,iOS 10 版本中处理推送通知。我在设备上收到了推送通知。当我点击通知时,它触发了 UNUserNotificationCenterDelegate 的委托,应用程序被打开,但它没有在用户信息中显示任何响应。我是否需要更改参数以在服务器端发送 iOS 10 中的推送。下面是我的代码。
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[application registerUserNotificationSettings:settings];
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionBadge | UNAuthorizationOptionSound | UNAuthorizationOptionAlert) completionHandler:^(BOOL granted, NSError * _Nullable error) {
if (!error) {
NSLog(@"request authorization succeeded!");
}
}];
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSLog(@"Notification is triggered");
completionHandler(UNNotificationPresentationOptionAlert);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler {
NSLog(@"Tapped in notification");
NSLog(@"%@",response.notification);
NSString *actionIdentifier = response.actionIdentifier;
if ([actionIdentifier isEqualToString:@"com.apple.UNNotificationDefaultActionIdentifier"] ||
[actionIdentifier isEqualToString:@"com.apple.UNNotificationDismissActionIdentifier"]) {
return;
}
}
在iOS9,
aps = {
alert = "Multi extra param push.";
badge = 0;
sound = default;
};
t = I;
url = "http://www.google.com";
并在 iOS 10
alert = "Multi extra param push.";
badge = 0;
sound = default;
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSLog(@"%@", notification.request.content.userInfo);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
didReceiveNotificationResponse:(UNNotificationResponse *)response
withCompletionHandler:(void(^)())completionHandler {
NSLog(@"%@", response.notification.request.content.userInfo);
}