微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在FCM中使用UNNotificationServiceExtension不会被调用

如何解决在FCM中使用UNNotificationServiceExtension不会被调用

我不知道可能是什么问题,但是FCM的任何推送都不会调用我的unnotificationserviceextension。我从python3脚本调用了FCM,到目前为止,它仍然有效(我收到了推送通知,但始终带有认文本,而不是修改后的文本)。

firebaseHeaders = {
    "Content-Type":"application/json","Authorization":"key=MY_KEY"
}

firebaseBody = {
    "to":device_token,"priority":"high","mutable-content":True,"apns-priority":5,"notification": { "title_loc_key":"push.goalReachedTitle","body_loc_key":"push.goalReachedContentRemote","body_loc_args":[str(entry['value']),entry['region']],"sound":"default","badge":1 },"data": { "values":data,"region":entry['region'],"value":entry['value'] }
}

firebaseResult = requests.post("https://fcm.googleapis.com/fcm/send",data=None,json=firebaseBody,headers=firebaseHeaders)

我的扩展程序也很基本(用于测试),我已经尝试将其删除并再次将其添加到我的主应用程序项目中。

class NotificationService: unnotificationserviceextension {

    var contentHandler: ((UNNotificationContent) -> Void)?
    var bestAttemptContent: UNMutableNotificationContent?

    override func didReceive(_ request: UNNotificationRequest,withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
        self.contentHandler = contentHandler
        bestAttemptContent = (request.content.mutablecopy() as? UNMutableNotificationContent)
        
        if let bestAttemptContent = bestAttemptContent {
            bestAttemptContent.title = bestAttemptContent.title + " [TEST 123]"            
            contentHandler(bestAttemptContent)
        }
    }
    
    override func 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.
        if let contentHandler = contentHandler,let bestAttemptContent =  bestAttemptContent {
            contentHandler(bestAttemptContent)
        }
    }
}

任何人都知道我仍然可以检查,测试或错过什么吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。