iOS 10 nicht call Notification Service Erweiterung

Habe ich versucht zu implementieren, das neue Notification Service Erweiterung, aber ich habe ein problem.

In meinem NotificationService.swift-Datei habe ich diesen code:

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]"

        print(bestAttemptContent.body)

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

Wenn ich eine push-Benachrichtigung die didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @entkommen (UNNotificationContent) -> Void) - Methode wird nie aufgerufen.

Vielleicht habe ich missverstanden, wie diese Erweiterung funktioniert?

  • Hi . hast du dies Problem gelöst ?
InformationsquelleAutor just | 2016-09-23
Schreibe einen Kommentar