【发布时间】:2017-12-26 20:48:48
【问题描述】:
因此,以下代码用于从图像的本地存储 url 附加图像。我签入Terminal 以查看图像是否已存储并且它确实存储了图像而没有任何问题。所以排除了 url 本身的任何问题。
do {
let attachment = try UNNotificationAttachment(identifier: imageTag, url: url, options: nil)
content.attachments = [attachment]
} catch {
print("The attachment was not loaded.")
}
与创建 UserNotification 相关的其他代码工作正常,因为它在正确的指定时间触发。
代码总是进入 catch 块。如果实施中有任何错误,任何人都可以指出我的错误。请帮忙。谢谢。
编辑:print(error.localizedDescription) 错误消息是Invalid attachment file URL。
Edit2 : print(error) 错误消息是 Error Domain=UNErrorDomain Code=100 "Invalid attachment file URL" UserInfo={NSLocalizedDescription=Invalid attachment file URL}
【问题讨论】:
-
catch语句中抛出了什么错误?将其添加到问题中。 -
@RoboticCat 感谢您的回复。错误显示
Invalid attachment file URL。我检查了 URL,它是有效的,并且能够使用终端查看存储在该位置的图像。
标签: ios swift usernotifications unnotificationserviceextension unnotificationattachment