Creating an image format with an unknown type is an error

My app uses a UIImagePickerController to allow the user to choose an image from their camera roll. This was all working fine up to iOS 9.3.4, but the iOS 10 betas now generate this error after the user has selected and tapped an image thumbnail from the picker: "[Generic] Creating an image format with an unknown type is an error". My picker is set to show kuTypeImage mediaTypes, but that's all I can think of doing.



I've added some NSLogs in the code for when the picker is displayed, and for when the user has selected an image in the imagePickerController:didFinishPickingMediaWithInfo: method. However, the error seems to be generated as soon as the image is selected, but before the picker is dismissed, so it appears before the imagePickerController:didFinishPickingMediaWithInfo: method.



Does anyone know how to fix this? As it stands, the image the user selectes is NOT returned to the method, so I can't use it.



I'm using iOS 10 beta 5 and Xcode 8 beta 5.



Here's the code:

- (void)showImageChooser
{
  UIImagePickerController *picker = [[UIImagePickerController alloc] init];
  [picker setDelegate:self];
  [picker setModalPresentationStyle:UIModalPresentationFullScreen];
  [picker setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
  [picker setAllowsEditing:NO];
  [picker setMediaTypes:[[NSArray alloc] initWithObjects:(NSString *)kUTTypeImage, nil]];
  self.imagePickerController = picker;

  NSLog(@"Presenting imagePicker");
  [self presentViewController:self.imagePickerController animated:YES completion:NULL];
  NSLog(@"imagePicker presented");
}



- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
  NSLog(@"didFinishPickingMediaWithInfo");
  UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

  / Do stuff with the image...

  [picker dismissViewControllerAnimated:YES completion:nil];
}


Thanks.

Replies

the same for me in Swift3/Xcode 8 beta 6.


in never arrive to:

private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {

discovered on swift3: (Hope it can help YOU in objC)



/ swift 3.0 suggestion

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {


/ swift 3.0 automatic translation

private func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [NSObject : AnyObject]) {



only the FIRST work.

The Objective-C method signature is:


- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *, id> *)info


It's correct as it is. I have deleted it and let Xcode auto-complete it. It is correct.

Got it working. Use...


  func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {


The Swift 3 fix-it initally wanted to add @nonobjc in front, so thats what was tripping things up when I changed AnyObject to Any . Best bet if you are converting an old project just start typing func imagePick... etc, and let Xcode write the rest.

Sorry, but this is an Objective-C issue, not Swift 3. As I said, I've already deleted the method signature and started typing it out to let Xcode finish it for me. The signature I posted above is correct. It's the only one available. This isn't an issue with Xcode 7 (latest version); it's only started appearing in the Xcode 8 betas.


Are you sure your fix (in Swift 3) means you don't see this error anymore: "[Generic] Creating an image format with an unknown type is an error"?


When I NSLog the info dictionary, I can see a UIImage object, and that's exactly what I expect to see, but the error appears immediately when the user has chosen an image, and before the method is reached. Also, even though this line (UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage]; ) takes the image from the dictionary, it isn't used, i.e. I pick an image, get the error and cannot use the image returned.

I had the same issue with it not calling the didFinishPicking... method until I changed the parameter to Any from AnyObject. Though it does call the method now and works to get the image, I am getting that same error message in Swift 3.0 with Beta 6.

Hi, sorry but this is NOT a Swift issue; it is an Objective-C issue. There is no "AnyObject" to change into "Any" in Objective-C.


Could people responding to this thread please not mention Swift? It's not helping to fix the actual issue. Thanks!

Bump! Same issue here on XCode 8 Beta, can someone from Apple help with this. Thanks.

Issue as darkpaw pointed out is with Objective C only not on Swift.

What do you mean by "I ... cannot use the image returned"? I tried your code in Xcode 8 beta 6, and the error is shown in the console, but (as you mentioned) the image is returned. I can assign it to the image property of a UIImageView and it is displayed. Works on iPhone 6 simulator and iPad Air device with iOS 10 beta 8.

I've debugged the code on Xcode 7.3.1 and Xcode 8 beta 6, and with iOS 9.3.5 and iOS 10 (latest beta). The issue with not being able to use the image seems to stem from an NSUserDefaults issue in Xcode 8b6/iOS 10: "[User Defaults] Failed to read values in CFPrefsPlistSource<0x1700ff680> (Domain: group.com.me.myapp, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null)): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd".


Bypassing the defaults fixes it, but that's not useful for my app, so I guess the problem is now this defaults error 😟

Found the defaults error solution here: https://forums.developer.apple.com/thread/51348


Basically, you need to add the team identifier in there, too:

From:

[[NSUserDefaults alloc] initWithSuiteName:"group.com.mycompany.myapp"];

To:

[[NSUserDefaults alloc] initWithSuiteName:"MYTEAMID.group.com.mycompany.myapp"];


However, this now wipes the values in the defaults (as it's now a new container), and I'm now having to work around a lot of errors caused by this. Gee, thanks, Apple.

I'm having the same issue. Are you now having to apend the team ID to the suite name in the main app as well whenever you access it for storage? I've tried adding a new container with the team id and that doesn't work since it keeps appending "group" in front of it (that's a requirement).


the lack on new documentation on how to do this is pretty frustrating, since all of my extensions are broken and this is now blocking our iOS 10 update.

I am having the same problem with Xcode 8 (8A208a) and iOS 10.0.1, the released versions.

This is what's happening at the moment:

- My app does not work correctly on an iPhone updated to iOS 10. This means an update is necessary or my customers will be stuck with a non-working app.

- My app works correctly on my iPhone with iOS 10 when it has been built using the latest version of Xcode 8 (build 8A218a). This is with the original suite name, and not with the team id added at the beginning of the string.


Sadly, it doesn't look like I can submit any updates to the App Store because iTunes Connect seems to think the version of Xcode I'm using is a beta. There are some posts about this on Stack Overflow, but I haven't found a fix as yet.