我在iOS的10媒體在附件10的iOS推送通知
我添加了一個通知服務擴展添加圖片到我的推送通知掙扎,並用下面的代碼:
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let urlString = request.content.userInfo["image-url"] as? String, let fileUrl = URL(string: urlString) {
URLSession.shared.downloadTask(with: fileUrl) { (location, response, error) in
if let location = location {
let options = [UNNotificationAttachmentOptionsTypeHintKey: kUTTypePNG]
if let attachment = try? UNNotificationAttachment(identifier: "", url: location, options: options) {
self.bestAttemptContent?.attachments = [attachment]
}
}
self.contentHandler!(self.bestAttemptContent!)
}.resume()
}
}
我從下面的第一個答案中得到了這段代碼。
我現在遇到的問題是收到通知,並顯示一個短暫的延遲,表明下載必須發生,但沒有顯示附件。
我假設serviceExtensionTimeWillExpire()
被調用,只是顯示bestAttempt
任何幫助是極大的讚賞。
我有我的APN有效載荷配置正確,我相信:
apns: {
aps: {
alert: {
title: "Title",
subtitle: "Subtitle",
body: "Body"
},
"mutable-content": 1
},
"image-url": "https://helloworld.com/image.png"
}
我似乎無法使用我的更新代碼的電影或GIF,只有圖像。有什麼建議麼? – nickjf89