我可以使用
修改远程通知的内容
“func didReceive(_ request:UNNotificationRequest,
withContentHandler contentHandler:@escaping(UNNotificationContent) - >无效)“通知服务扩展。但无法下载图像或电影,并将其作为附件添加到内容。
我们如何使用此方法在远程通知中附加媒体。
答案 0 :(得分:0)
我写了一个扩展来简化流程,请看这里: UNNotificationAttachment with UIImage or Remote URL
然后你可以像这样包含图像
let identifier = ProcessInfo.processInfo.globallyUniqueString
let content = UNMutableNotificationContent()
content.title = "Hello"
content.body = "World"
if let attachment = UNNotificationAttachment.create(identifier: identifier, image: myImage, options: nil) {
// where myImage is any UIImage that follows the
content.attachments = [attachment]
}
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 120.0, repeats: false)
let request = UNNotificationRequest.init(identifier: identifier, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in
// handle error
}