相关疑难解决方法(0)

Notificaton服务扩展无法正常工作

当我发送mutable-content时,没有显示通知:1,推送有效负载既不会到达Notification服务扩展中的断点,但是如果没有显示可变内容推送,Notification内容扩展也正常工作.我没有修改Notification服务扩展中的代码,它是xcode生成的默认代码.在创建通知服务扩展时我是否遗漏了某些内容,或者可能是设备设置的问题.我几天前在同一台设备上进行了测试,通知服务扩展工作正常.

以下是我的服务扩展代码

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

notifications apple-push-notifications ios ios10 serviceextension

3
推荐指数
2
解决办法
4470
查看次数