Question

I am trying to have an email dialogue show up directly after someone chooses a photo via the UIImagePickerController. I can't get it to pop up directly afterwards. Am I doing something wrong? Eventually I will have the photo be an attachment, but thats not the hard part. I can get both the email and photo modals to show individually, just not sequentially automatically. Thanks!

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
// Hide the dialouge
[picker dismissModalViewControllerAnimated:YES];
[self becomeFirstResponder];

MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"test"];
[controller setMessageBody:@"test" isHTML:NO];

[self presentModalViewController:controller animated:YES];

}

Was it helpful?

Solution

Because you are using animation to hide your image picker.

The UIImagePickerController is not actually dismissed when you are trying to present your MFMailComposeViewController, that's why you get an error.

You can just change you code

[picker dismissModalViewControllerAnimated:YES];

to

[picker dismissModalViewControllerAnimated:NO]; // (set Animated to "NO") 

to workaround this problem.

P.S. I am also not sure why you are adding

[self becomeFirstResponder];

there, but it seems not necessary.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top