更改推送通知警报消息
答
试着改变你通知服务扩展代码:
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)
}
}
+0
我试图做bestAttemptContent.title =“我真棒”,但标题显然是尽管@仍然是我的“警戒”。@ – Happiehappie
+0
我做了一些挖掘和测试,显然要改变的属性是身体而不是标题?只是想澄清你。 – Happiehappie
+0
@Happiehappie当然,如果'身体'工程然后使用它。我只是把'title'作为例子,因为它取决于你的PN实现。 – njuri
好问题,我从来没有遇到过这样的问题......(Y) –