0

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()
}
Joon. P
  • 2,238
  • 7
  • 26
  • 53
  • Just share the images to Today extension..Using Build Phases->Copy Bundle Resources.. Then store the image name in NSUserDefaults – Anbu Raj Aug 11 '15 at 10:07

1 Answers1

0

Convert the image to a NSData object with UIImageJPEGRepresentation. Store the NSData object in NSUserDefaults. In the extension get back the image with imageWithData(_:).

dasdom
  • 13,975
  • 2
  • 47
  • 58