[英]Modify the Push notification content from Userinfo in ios
When receiving a notification, I want to change the user info content before showing in mobile notification in iOS. 收到通知后,我想在iOS中的移动通知中显示之前更改用户信息内容。
"aps": {
"alert": {
"body": "hello",
"sound": "Default"
"badge": "1"
}
}
Example I want to show world instead of hello . 示例我想展示世界而不是你好 。
Is this possible in iOS 10? 这在iOS 10中是否可行?
You can implement notification extension for it. 您可以为它实现通知扩展。 Here is link : Notification Extension 这是链接: 通知扩展
You must implement the didReceive(_:withContentHandler:) method and use it to process incoming notifications. 您必须实现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)
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.