更改推送通知警报消息

时间:2017-04-08 12:23:40

标签: ios swift swift3 ios10

如何更改推送通知的提醒信息。我需要处理Unicode字符串,如屏幕截图所示。 screenshot

我尝试检查我的通知服务扩展程序,但我找不到任何方法来处理userInfo [" alert"]属性。

1 个答案:

答案 0 :(得分:2)

尝试更改通知服务扩展代码:

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
        // Convert received string
        let data = bestAttemptContent.body.data(using: .utf8)!
        // Apply encoded string
        bestAttemptContent.body = String(data: data, encoding: .utf16)

        contentHandler(bestAttemptContent)
    }
}