【发布时间】:2017-10-05 17:13:27
【问题描述】:
我正在将 UIImage 保存到 Core Data。所以首先,我将它转换为 NSData,然后保存它。
我需要在图片保存后获取图片的 URL。我这样做是因为我想安排带有附件的本地通知,而唯一的方法,AFAIK,就是使用 URL。
这是我的代码:
//my image:
var myImage: UIImage?
var imageData: NSData?
if let image = myImage {
imageData = UIImageJPEGRepresentation(image, 0.5)! as NSData
}
myEntity.setValue(imageData, forKey: "image")
这就是我应该在通知中添加附件的方式:UNNotificationAttachment.init(identifier: String, url: URL>, options: [AnyHashable : Any]?)
当用户点击按钮保存图像时,我正在保存图像并手动安排通知。
如果您需要更多信息,请告诉我。
【问题讨论】:
-
将图片保存到本地,并将其url保存到CoreData
-
UIMagagedDocument 似乎是使用核心数据的 UIDocument 的子类,它以 url 启动以获取上下文。我不是很熟悉,但你可能想研究一下。
标签: ios swift core-data unnotificationattachment usernotificationsui