美文网首页
iOS12中推送通知新特性-分组

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

作者: 小星星吃KFC | 来源:发表于2019-03-07 16:02 被阅读0次

    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"
    
        }
    
    

    相关文章

      网友评论

          本文标题:iOS12中推送通知新特性-分组

          本文链接:https://www.haomeiwen.com/subject/moocpqtx.html