gpt4 book ai didi

ios - 无法使用 iOS 10 中的通知服务扩展在远程通知中附加媒体

转载 作者:行者123 更新时间:2023-11-28 08:18:18 25 4
gpt4 key购买 nike

我可以使用
修改远程通知的内容"func didReceive(_ request: UNNotificationRequest,withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void)"通知服务扩展。但无法下载图像或电影并将它们作为附件添加到内容中。

我们如何使用此方法在远程通知中附加媒体。

最佳答案

我写了一个扩展来简化这个过程,看这里: 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
}

关于ios - 无法使用 iOS 10 中的通知服务扩展在远程通知中附加媒体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41979988/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com