iOS12通知分组,效果如图
图片.png
代码,在iOS10 UNNotificationServiceExtension 中添加代码(如何添加UNNotificationServiceExtension 自行谷歌).
- (void)didReceiveNotificationRequest:(UNNotificationRequest *)request
withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
self.contentHandler = contentHandler;
self.bestAttemptContent = [request.content mutableCopy];
self.bestAttemptContent.title = [NSString stringWithFormat:@"%@ [modified]", self.bestAttemptContent.title];
NSDictionary *dict = request.content.userInfo;
/**aps中取值,服务端aps推送通知*/
self.bestAttemptContent.threadIdentifier = dict[@"aps"][@"threadIdentifier"];
if (@available(iOS 12.0, *)) {
self.bestAttemptContent.summaryArgument = dict[@"aps"][@"summaryArgument"];
self.bestAttemptContent. summaryArgumentCount = [dict[@"aps"][@"thread-id"] integerValue];
}
self.contentHandler(self.bestAttemptContent);
}
服务端aps格式
{
"aps": {
"alert": {
"title": "推送测试",
"body": "推送内容",
"type": 1
},
"badge": 1,
"sound": "default",
"mutable-content": 1,
"category": "GENERAL",
"thread-id": 1,
"threadIdentifier": "game",
"summaryArgument": "NBA"
}
网友评论