相关疑难解决方法(0)

iOS 10不会调用Notification Service Extension

我试图实现新的Notification Service Extension,但我遇到了问题.

在我的NotificationService.swift文件中,我有这样的代码:

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 …
Run Code Online (Sandbox Code Playgroud)

ios swift ios-extensions ios10

14
推荐指数
5
解决办法
9459
查看次数

标签 统计

ios ×1

ios-extensions ×1

ios10 ×1

swift ×1