更改推送通知警报消息
Change push notification alert message
如何更改推送通知的提醒消息。我需要处理 Unicode 字符串,如屏幕截图所示。
我尝试检查我的通知服务扩展,但找不到任何方法来处理 userInfo["alert"] 属性.
尝试更改您的通知服务扩展代码:
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)
}
}
如何更改推送通知的提醒消息。我需要处理 Unicode 字符串,如屏幕截图所示。
我尝试检查我的通知服务扩展,但找不到任何方法来处理 userInfo["alert"] 属性.
尝试更改您的通知服务扩展代码:
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)
}
}