HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了ios – Notificaton服务扩展无法正常工作大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
当我发送mutable-content时,没有显示通知:1,推送有效负载既不会到达Notification服务扩展中的断点,但是如果没有显示可变内容推送,Notification内容扩展也正常工作.我没有修改Notification服务扩展中的代码,它是 xcode生成代码.在创建通知服务扩展时我是否遗漏了某些内容,或者可能是设备设置的问题.我几天前在同一台设备上进行了测试,通知服务扩展工作正常.

以下是我的服务扩展代码

import UserNotifications

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 {
            // Modify the notification content here...
            bestAttemptContent.title = "\(bestAttemptContent.titlE) [modified]"

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

编辑1:下面是我的推送有效载荷

{  
   "aps":{  
      "sound":"default","mutable-content": 1,"category": "myCategory","alert":{  
         "body":"this is a custom push","subtitle":"subtitle of the push","title":"Push Test"
      }

   }
}

edit1:问题出现在10.2.1上运行的特定设备上,我检查了运行在10.2上的其他设备,它触发了Notification服务扩展.

解决方法

最后我能够解决这个问题.我不确定是什么导致了这个问题,但经过一些实验后,我意识到不仅我的服务扩展,而且所有其他安装的应用程序的服务扩展都无法正常工作,并且在发送带有“mutable-content:1”的推送有效负载时,未显示通知.重新启动设备后,它开始正常工作.我正在使用iPhone 6s.

大佬总结

以上是大佬教程为你收集整理的ios – Notificaton服务扩展无法正常工作全部内容,希望文章能够帮你解决ios – Notificaton服务扩展无法正常工作所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。