收到通知时,我想在 iOS 的移动通知中显示之前更改用户信息内容。
"aps": {
"alert": {
"body": "hello",
"sound": "Default"
"badge": "1"
}
}
示例我想显示world而不是hello。
这在 iOS 10 中可能吗?
收到通知时,我想在 iOS 的移动通知中显示之前更改用户信息内容。
"aps": {
"alert": {
"body": "hello",
"sound": "Default"
"badge": "1"
}
}
示例我想显示world而不是hello。
这在 iOS 10 中可能吗?
您可以为它实现通知扩展。这是链接:通知扩展
您必须实现 didReceive(_:withContentHandler:) 方法并使用它来处理传入的通知。
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)
}
}