Ios 更改推送通知警报消息
如何更改推送通知的警报消息。我需要处理Unicode字符串,如屏幕截图所示Ios 更改推送通知警报消息,ios,swift,swift3,ios10,Ios,Swift,Swift3,Ios10,如何更改推送通知的警报消息。我需要处理Unicode字符串,如屏幕截图所示 我尝试检查通知服务扩展,但找不到任何方法来处理userInfo[“alert”]属性。尝试更改通知服务扩展代码: override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.cont
我尝试检查通知服务扩展,但找不到任何方法来处理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)
}
}
好问题,我从来没有遇到过这样的问题…(y)我试过做bestAttemptContent.title=“我很棒”,但标题显然仍然是我的“警惕”。@我做了一些挖掘和测试,显然要更改的属性是body而不是title?只是想跟你澄清一下。@Happiehappie当然,如果
body
有效,那么就用它。我刚刚举了title
作为例子,因为它取决于您的PN实现?我愿意接受您的答案。我已将代码片段更改为使用正文
,如果它有助于您也可以对答案进行投票:)