如何将 UIImage 传递给 iOS、swift 中的 Today Extension?
How to pass UIImage to Today Extension in iOS, swift?
有没有办法使用 NSSharedDefaults 以这种方式将 UIImage 传递给 Today Extension? :
if let sharedDefaults = NSUserDefaults(suiteName: "group.example.TodayExtension") {
// Below line crashes, since .setObject cannot have UIImage as a parameter
sharedDefaults.setObject(image, forKey: "imageKey") // image = UIImage object
sharedDefaults.synchronize()
}
使用 UIImageJPEGRepresentation. Store the NSData
object in NSUserDefaults
. In the extension get back the image with imageWithData(_:).
将图像转换为 NSData
对象
有没有办法使用 NSSharedDefaults 以这种方式将 UIImage 传递给 Today Extension? :
if let sharedDefaults = NSUserDefaults(suiteName: "group.example.TodayExtension") {
// Below line crashes, since .setObject cannot have UIImage as a parameter
sharedDefaults.setObject(image, forKey: "imageKey") // image = UIImage object
sharedDefaults.synchronize()
}
使用 UIImageJPEGRepresentation. Store the NSData
object in NSUserDefaults
. In the extension get back the image with imageWithData(_:).
NSData
对象