swift 友盟推送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...
            let apsDic = request.content.userInfo["aps"] as! [String: Any]
            let attachUrl = apsDic["image"]
//            let category = apsDic["category"] //这里取消注释,需要在配置消息的时候加对应的category
//            bestAttemptContent.categoryIdentifier = category as! String
           // bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"

            let session = URLSession.shared
            let url = URL.init(string: attachUrl as! String)!
            let downloadTask: URLSessionDownloadTask = session.downloadTask(with: url) { (url, urlResponse, error) in
                let caches = NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).last
                let file = "\(caches!)/\((urlResponse?.suggestedFilename)!)"
                let mgr = FileManager.default
                try! mgr.moveItem(atPath: url!.path, toPath: file)
                if file != "" {
                    let attch = try! UNNotificationAttachment.init(identifier: "photo", url: URL.init(string: "file://\(file)")!, options: [:])
                    bestAttemptContent.attachments = [attch]
                }
                contentHandler(bestAttemptContent)
            }
            downloadTask.resume()
        }
    }
2. 右图支持http
在notificationService文件夹里面的info.plist里面用source code打开第五行添加:
<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <true/>
    </dict>
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容