2017-04-08 193 views
2

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

我想检查我的通知服务扩展,但我找不到任何办法来处理用户信息[“警报”]属性。

+0

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

回答

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

我试图做bestAttemptContent.title =“我真棒”,但标题显然是尽管@仍然是我的“警戒”。@ – Happiehappie

+0

我做了一些挖掘和测试,显然要改变的属性是身体而不是标题?只是想澄清你。 – Happiehappie

+0

@Happiehappie当然,如果'身体'工程然后使用它。我只是把'title'作为例子,因为它取决于你的PN实现。 – njuri