UIImagePicker controller has been working fine forever in my code while selecting an image from the UIImagePickerController.But all of a sudden with the iOS 12.2 Betas, info[UIImagePickerController.InfoKey.imageURL] contains nil for all images!! Which means I can't obtain the URL for the image & use it!!func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
picker.dismiss(animated: true, completion: { [unowned self] in
guard info[UIImagePickerController.InfoKey.mediaType] != nil else { return }
let mediaType = info[UIImagePickerController.InfoKey.mediaType] as! CFString
if mediaType == kUTTypeImage {
if var imageURL = info[UIImagePickerController.InfoKey.imageURL] as? URL {
self.employImageAtURL(imageURL)
} else {
fatalError("Failed to get imageURL") //CALLED EVERY TIME NOW!!
}
}
})
}Is anyone else seeing this problem? Please help!
Post
Replies
Boosts
Views
Activity
Since upgrading to Swift 4.2 I've found that many of the NSKeyedUnarchiver and NSKeyedArchiver methods have been deprecated and we must now use the type method static func unarchivedObject<DecodedObjectType>(ofClass: DecodedObjectType.Type, from: Data) -> DecodedObjectType? to unarchive data.I have managed to successfully archive an Array of my bespoke class WidgetData, which is an NSObject subclass:private static func archiveWidgetDataArray(widgetDataArray : [WidgetData]) -> NSData {
guard let data = try? NSKeyedArchiver.archivedData(withRootObject: widgetDataArray as Array, requiringSecureCoding: false) as NSData
else { fatalError("Can't encode data") }
return data
}The problem comes when I try to unarchive this data:static func loadWidgetDataArray() -> [WidgetData]? {
if isKeyPresentInUserDefaults(key: USER_DEFAULTS_KEY_WIDGET_DATA) {
if let unarchivedObject = UserDefaults.standard.object(forKey: USER_DEFAULTS_KEY_WIDGET_DATA) as? Data {
//THIS FUNCTION HAS NOW BEEN DEPRECATED:
//return NSKeyedUnarchiver.unarchiveObject(with: unarchivedObject as Data) as? [WidgetData]
guard let nsArray = try? NSKeyedUnarchiver.unarchivedObject(ofClass: NSArray.self, from: unarchivedObject as Data) else {
fatalError("loadWidgetDataArray - Can't encode data")
}
guard let array = nsArray as? Array else {
fatalError("loadWidgetDataArray - Can't gat Array")
}
return array
}
}
return nil
}But this fails, as using Array.self instead of NSArray.self is disallowed. What am I doing wrong and how can I fix this to unarchive my Array?