iOS12中推送通知新特性-分组

2019-03-07  本文已影响0人  小星星吃KFC

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"

    }

上一篇 下一篇

猜你喜欢

热点阅读