美文网首页
iOS NotificationServiceExtension

iOS NotificationServiceExtension

作者: 唐人街的乞丐 | 来源:发表于2023-01-16 17:49 被阅读0次

    后台语音播报会用到此功能或者其他图片或音视自定义推送会使用到NotificationServiceExtension

    后台推送的时候需要添加mutable-content=1字段

    创建NotificationServiceExtension
    file--new--target


    image.png

    选择Notification Service Extension


    image.png

    下一步


    image.png
    下一步
    image.png

    此时多了一个


    image.png

    需要做的自定义处理

    - (void)didReceiveNotificationRequest:(UNNotificationRequest *)request withContentHandler:(void (^)(UNNotificationContent * _Nonnull))contentHandler {
        self.contentHandler = contentHandler;
        self.bestAttemptContent = [request.content mutableCopy];
        
    
        
        self.contentHandler(self.bestAttemptContent);
    }
    
    - (void)serviceExtensionTimeWillExpire {
        // Called just before the extension will be terminated by the system.
        // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
        self.contentHandler(self.bestAttemptContent);
    }
    

    如果需要做http网络请求,需要TestNotificationServiceExtension 里面的Info添加App Transport Security Settings

    TestNotificationServiceExtension的Info和项目里的数据不互通
    如果需要跟项目里的数据互通需要创建App Groups

    参考 App Groups 创建 https://www.jianshu.com/p/3fbaa8143a75?v=1675044627433

    相关文章

      网友评论

          本文标题:iOS NotificationServiceExtension

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