在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 (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...