简体   繁体   English

如何将UIImage快速传递给iOS中的Today扩展?

[英]How to pass UIImage to Today Extension in iOS, swift?

Is there a way to pass UIImage over to Today Extension using NSSharedDefaults in such way? 有没有办法通过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()
}

Convert the image to a NSData object with UIImageJPEGRepresentation . 使用UIImageJPEGRepresentation将图像转换为NSData对象。 Store the NSData object in NSUserDefaults . NSData对象存储在NSUserDefaults In the extension get back the image with imageWithData(_:) . 在扩展名中,使用imageWithData(_ :)返回图像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM