emailing an image picked by user from UIpickerController
what i want to in my app is have a user select an image in their library, then attach that image to an email and send it.
i have read multiple examples, but cant seem to get any to work with this
- (IBAction)buttonTouched:(id)sender;
{ // Create image picker controller UIImagePickerController *imagePicker = [[UIImagePickerController allo开发者_开发知识库c] init];
// Set source to the camera
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// Delegate is self
imagePicker.delegate = self;
// Allow editing of image ?
// imagePicker.allowsImageEditing = NO;
// Show image picker
[self presentModalViewController:imagePicker animated:YES];
}
this is the code i tried to get the image at a button press. but how do i get that into the email, i just dont understand how this returns the image and in what format
any help would be very welcome :)
i have the same request some weeks ago, you have to display the UIImagePickerController and let the user select an image, and save it in a variable.
UIImage *image;
Next implemente the method:
// Displays an email composition interface inside the application. Populates all the Mail fields.
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"This is my subject"];
// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"personOne@example.com"];
[picker setToRecipients:toRecipients];
// Attach an image to the email
NSData *myData = UIImagePNGRepresentation(self.image);
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"myImage"];
[self presentModalViewController:picker animated:YES];
[picker release];
}
精彩评论