Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was having the same problem when i wanted to present an MFMailComposeViewController immediately after dismissing the UIImagePickerController. Heres what i did:</p> <ol> <li><p>I removed the <code>[imagePicker release];</code> statement from where i was presenting the image picker and put it in didFinishPickingMedia callback.</p></li> <li><p>I used <code>[self performSelector:@selector(presentMailComposer:) withObject:image afterDelay:1.0f];</code></p></li> </ol> <p>Here's my code: Displaying Image Picker</p> <p><code> if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) { NSArray *media = [UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary];</p> <pre><code> if ([media containsObject:(NSString*)kUTTypeImage] == YES) { UIImagePickerController *picker = [[UIImagePickerController alloc] init]; [picker setMediaTypes:[NSArray arrayWithObject:(NSString *)kUTTypeImage]]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; [self presentModalViewController:picker animated:YES]; //[picker release]; } } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unavailable!" message:@"Could not open the Photo Library." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } </code></pre> <p></code></p> <p>Image Picker Delegate Callback - didFinishPickingMedia</p> <p><code> NSString *mediaType = [info valueForKey:UIImagePickerControllerMediaType];</p> <pre><code>if([mediaType isEqualToString:(NSString*)kUTTypeImage]) { UIImage *photoTaken = [info objectForKey:@"UIImagePickerControllerOriginalImage"]; //Save Photo to library only if it wasnt already saved i.e. its just been taken if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) { UIImageWriteToSavedPhotosAlbum(photoTaken, self, @selector(image:didFinishSavingWithError:contextInfo:), nil); } //Pull up MFMailComposeView Controller [self performSelector:@selector(composeMailWithPhoto:) withObject:photoTaken afterDelay:1.0f]; } [picker dismissModalViewControllerAnimated:YES]; [picker release]; </code></pre> <p></code></p> <p>Display Mail Composer View</p> <p><code> if ([MFMailComposeViewController canSendMail]) {</p> <pre><code> MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init]; mailPicker.mailComposeDelegate = self; // Fill out the email fields and Attach photograph to mail static NSString *imageType = @"image/jpeg"; NSString *imageName = [NSString stringWithString:@"MyCoffeeCup.jpg"]; NSData *imageData = UIImageJPEGRepresentation(image, 1.0); [mailPicker addAttachmentData:imageData mimeType:imageType fileName:imageName]; [mailPicker setToRecipients:[NSArray arrayWithObject:@"hello@xische.com"]]; [self presentModalViewController:mailPicker animated:YES]; //[self.navigationController pushViewController:mailPicker animated:YES]; [mailPicker release]; } else { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unavailable!" message:@"This device cannot send emails." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; [alert release]; } </code></pre> <p></code></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload