presentModalViewController:Animated is deprecated in ios6

IphoneObjective CUiimageUiimagepickercontroller

Iphone Problem Overview


I am using the following code for an image picker. But when I run it in the simulator, I have a memory leak and I get a warning about presentModalViewcontroller:animated being deprecated in iOS6. I also get dismissModalViewController:animated deprecated. I'm using the SDK 6.1.

Code for ImagePicker:

- (void)showAlbum:(id)sender { 
    imagePicker=[[UIImagePickerController alloc]init];
    imagePicker.delegate = self;
    imagePicker.allowsEditing =NO;
    imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [self presentModalViewController:imagePicker animated:YES];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    //release picker
    [picker dismissModalViewControllerAnimated:YES];
}

Iphone Solutions


Solution 1 - Iphone

Use this line & check:

[self presentViewController:imagePicker animated:YES completion:nil];

Solution 2 - Iphone

[[Picker presentingViewController] dismissViewControllerAnimated:YES completion:nil];

Instead of

 [[Picker parentViewControl] dismissModalViewControllerAnimated:YES];

and

[self presentViewController:picker animated:YES completion:nil];

Instead of

[self presentModalViewController:picker animated:YES];

Solution 3 - Iphone

if ([self respondsToSelector:@selector(presentViewController:animated:completion:)])
{
    [self presentViewController:objSignupViewController animated:^{} completion:nil];
}
else
{
    [self presentModalViewController:objSignupViewController animated:YES];
}

Solution 4 - Iphone

As Vishal mentioned

> [self presentViewController:imagePicker animated:YES completion:nil]; > [self dismissViewControllerAnimated:YES completion:nil];

make sure you have added "completion:nil" as well

Solution 5 - Iphone

Use:

[self presentViewController:imagePicker animated:YES completion:nil];

And then for your dismissal modal use:

[self dismissViewControllerAnimated:controller completion:nil];

or

[self dismissViewControllerAnimated:YES completion:nil];

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionRamView Question on Stackoverflow
Solution 1 - IphoneVishalView Answer on Stackoverflow
Solution 2 - IphonedeepeshView Answer on Stackoverflow
Solution 3 - IphoneMohitView Answer on Stackoverflow
Solution 4 - IphoneKrishna SapkotaView Answer on Stackoverflow
Solution 5 - IphoneBrainyMonkeyView Answer on Stackoverflow