大佬教程收集整理的这篇文章主要介绍了ios – Notificaton服务扩展无法正常工作,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
以下是我的服务扩展代码
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服务扩展.
以上是大佬教程为你收集整理的ios – Notificaton服务扩展无法正常工作全部内容,希望文章能够帮你解决ios – Notificaton服务扩展无法正常工作所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。