Is there a way to pass UIImage over to Today Extension using NSSharedDefaults in such way? :
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()
}
Convert the image to a NSData
object with UIImageJPEGRepresentation . Store the NSData
object in NSUserDefaults
. In the extension get back the image with imageWithData(_:) .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.