【问题标题】:Change push notification alert message更改推送通知警报消息
【发布时间】:2017-04-08 12:23:39
【问题描述】:

如何更改推送通知的警报消息。我需要处理 Unicode 字符串,如屏幕截图所示。

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

【问题讨论】:

  • 好问题,我从来没有遇到过这样的问题...(y)

标签: ios swift swift3 ios10


【解决方案1】:

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

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)
    }
}

【讨论】:

  • 我尝试过 bestAttemptContent.title = "I am awesome" 但标题显然仍然是我的“警告”@.@
  • 我做了一些挖掘和测试,显然要更改的属性是正文而不是标题?只是想和你澄清一下。
  • @Happiehappie 当然,如果body 有效,那么就使用它。我只是以title 为例,因为它取决于您的 PN 实现。
  • 现在,既然我开始了这个帖子,你介意把你的sn-p改成body吗?我愿意接受你的回答。
  • 我已将 sn-p 更改为使用 body,如果它对您有帮助,您也可以为答案投票:)
猜你喜欢
  • 1970-01-01
  • 2017-01-19
  • 1970-01-01
  • 1970-01-01
  • 2013-09-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多