2017-04-08 190 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