0

Using presentModalViewController with UIImagePickerController causing Crash on iOS 5 (its running fine on version<5), i am trying to get all the albums on the device, using 'UIImagePickerControllerSourceTypeSavedPhotosAlbum' is only getting the Camera images, so when i change the sourceType to 'UIImagePickerControllerSourceTypePhotoLibrary' it crashes, i appreciate any help, here is my code:

float version = [[[UIDevice currentDevice] systemVersion] floatValue];
    if(version < 5) 
        imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    else                        
        imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        //imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;

    [self presentModalViewController:imgPicker animated:YES];
Kazmi
  • 593
  • 1
  • 6
  • 24
  • when using iOS 5 it crashes on this line: [self presentModalViewController:imgPicker animated:YES]; – Kazmi Jan 26 '12 at 14:46
  • Whats the crash message / exception information? – Dennis Bliefernicht Jan 26 '12 at 14:49
  • I have the very same problem (iOS5, iPad, Landscape). Presenting the UIImagePickerControllerSourceTypeCamera works just fine, but UIImagePickerControllerSourceTypePhotoLibrary and UIImagePickerControllerSourceTypeSavedPhotosAlbum don't. Did you find a solution yet? – cschuff Jan 27 '12 at 09:27
  • I found another post saying the `UIImagePickerController` you present should be stored as a variable in the presenting class to prevent it from being deallocated too early. This unfortunately didn't help me... – cschuff Jan 27 '12 at 09:29
  • 1
    That solved my problem on iPad. It indeed needs to be created as a popover: http://stackoverflow.com/questions/9015155/how-to-use-uiimagepickercontroller-in-ipad – cschuff Jan 27 '12 at 09:36

1 Answers1

1

From the official doc:

To use an image picker controller containing its default controls, perform these steps:

  1. Verify that the device is capable of picking content from the desired source. Do this calling the isSourceTypeAvailable: class method, providing a constant from the “UIImagePickerControllerSourceType” enum.

  2. Check which media types are available, for the source type you’re using, by calling the availableMediaTypesForSourceType: class method. This lets you distinguish between a camera that can be used for video recording and one that can be used only for still images.

  3. Tell the image picker controller to adjust the UI according to the media types you want to make available—still images, movies, or both—by setting the mediaTypes property.

  4. Present the user interface by calling the presentViewController:animated:completion: method of the currently active view controller, passing your configured image picker controller as the new view controller.

    On iPad, present the user interface using a popover. Doing so is valid only if the sourceType property of the image picker controller is set to UIImagePickerControllerSourceTypeCamera. To use a popover controller, use the methods described in “Presenting and Dismissing the Popover” in UIPopoverController Class Reference.

  5. When the user taps a button to pick a newly-captured or saved image or movie, or cancels the operation, dismiss the image picker using your delegate object. For newly-captured media, your delegate can then save it to the Camera Roll on the device. For previously-saved media, your delegate can then use the image data according to the purpose of your app

Maybe point 4 is causing troubles.

basvk
  • 4,437
  • 3
  • 29
  • 49
  • it is saying "EXC_BAD_ACCESS" , it works fine if when i change the source type to following, thanks for your response; imgPicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; – Kazmi Jan 26 '12 at 15:37
  • i even tried this line of code but still not working, cant figure out why :( :: [self presentViewController:imgPicker animated:YES completion:^{NSLog(@"Photo Albums Presented");}]; – Kazmi Jan 26 '12 at 16:13
  • 2
    Are you testing this on an iPad or iPhone? Because on iPad, UIImagePickerController must be presented via UIPopoverController – basvk Jan 26 '12 at 16:19
  • thanks, but i am using iPhone with iOS 5 and the code is not working, any idea how i can make it work? i appreciate your continuos replies. – Kazmi Jan 27 '12 at 09:33
  • its resolved now, Thanks alot for the help, i was missing one of the steps you mentioned above. – Kazmi Jan 27 '12 at 10:08