如何在推送通知显示为推送通知之前删除html格式?

时间:2018-07-12 03:06:24

标签: ios swift firebase push-notification appdelegate

我尝试将Firebase(FCM)推送通知以html格式发送到我的设备,其中包括推送通知的标题和正文。它在推送通知上直接显示为html格式,如下图所示: enter image description here

我想删除标题和消息中的html格式,使其显示为普通文本(示例粗体将显示为粗体,而前面不显示b)。我试图在:

中捕获推送通知的标题和正文
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {

    // Access userInfo
    if application.applicationState == .active {
        if let aps = userInfo["aps"] as? NSDictionary {
            let alert = aps["alert"] as! NSDictionary
            let body = alert["body"] as! String
            let title = alert["title"] as! String
        }
    }
    completionHandler(.newData)
}

它可以获得推送通知的标题和正文。

并且我已经创建了html格式转换为普通文本:

func convertHtml() -> NSAttributedString{
    guard let data = data(using: .utf8) else { return NSAttributedString() }
    do{
        return try NSAttributedString(data: data, options: [NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: String.Encoding.utf8.rawValue], documentAttributes: nil)
    }catch{
        return NSAttributedString()
    }
}

我想要的是如何在推送通知中将html格式的文本转换为普通文本,然后再显示为推送通知?

0 个答案:

没有答案
相关问题