如何解决NotificationServiceExtension停止工作
我正在尝试使用unnotificationserviceextension实现应用程序徽章解决方案。当我实施基本解决方案时。它显示的是[modified]标题,但是当我添加应用程序分组解决方案并尝试访问UserDefaults时,它将停止工作
import UserNotifications
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)
let defaults = UserDefaults(suiteName: "group.hu.focifc.focifc")
var count: Int = defaults!.value(forKey: "count") as! Int
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
//bestAttemptContent.badge = count as? NSNumber
//count = count + 1
//defaults?.set(count,forKey: "count")
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)
}
}
}
当我删除或取消注释... var count:Int ...行时,它没有完成工作。
有什么主意吗?
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。