Badge NotificationServiceExtension停止工作

Badge NotificationServiceExtension停止工作,badge,remote-notifications,unnotificationserviceextension,Badge,Remote Notifications,Unnotificationserviceextension,我正在尝试使用UNNotificationServiceExtension实现应用程序标签解决方案。当我实现基本解决方案时。它显示的是[modified]标题,但当我添加应用程序分组解决方案并尝试访问UserDefaults时,它停止工作 import UserNotifications 类NotificationService:UNNotificationServiceExtension{ var contentHandler: ((UNNotificationContent) ->

我正在尝试使用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)
    }
}
}

当我删除或取消注释。。。变量计数:Int。。。这不是工作

有什么想法吗