I created custom photo album for capturing photos. And i invoked this album inside my app. After clicking button the album is invoked. But i can't share this image to mail. I used MFMailComposeViewController
for sending.
code:
photopick= [UIButton buttonWithType:UIButtonTypeCustom];
[photopick setImage:[UIImage imageNamed:@"photo.png"] forState:UIControlStateNormal];
// [overlayButton setFrame:CGRectMake(80, 420, 60, 30)];
[photopick setFrame:CGRectMake(10, 10, 80, 50)];
[photopick addTarget:self action:@selector(showAlbum:) forControlEvents:UIControlEventTouchUpInside];
[[self view] addSubview:photopick];
-(void)showAlbum:(id)sender{
imagePicker=[[UIImagePickerController alloc]init];
imagePicker.delegate = self;
imagePicker.allowsEditing =NO;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// imagePicker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:imagePicker animated:YES];
}
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
//release picker
[picker dismissModalViewControllerAnimated:YES];
}
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
//set image
[self.navigationController.navigationBar setHidden:NO];
// newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
newImage = [[UIImageView alloc] initWithImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
[newImage setFrame:CGRectMake(0, 0, 320, 568)];
// [newImage setUserInteractionEnabled:YES];
[self.view addSubview:newImage];
// [newImage release];
[picker dismissModalViewControllerAnimated:YES];
}
After picking image i have other button to send newImage (album image) to mail:
-(void)send:(id)sender{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:@"My image"];
UIImage *roboPic = [UIImage imageNamed:@"RobotWithPencil.jpg"];
NSData *imageData = UIImageJPEGRepresentation(roboPic, 1);
[picker addAttachmentData:imageData mimeType:@"image/jpg" fileName:@"RobotWithPencil.jpg"];
NSString *emailBody = @"This is a cool image of a robot I found. Check it out!";
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
}
But how can i set album image to inside MFMailComposeViewController
. Some docs mentioned used [UIImage imageNamed:@"img.png"];
Here i don't have imageName. I have images from album
Try with the following link
you can set Multiple images in Messagebody using for loop.
set your message body with this function
- (NSString *)messageBody
{
// if we couldn't fetch the app information, use a simple fallback template
if (self.applicationSellerName==nil) {
// Fill out the email body text
NSMutableString *emailBody = [NSMutableString stringWithFormat:@"<div> \n"
"<p style=\"font:17px Helvetica,Arial,sans-serif\">%@</p> \n"
"<h1 style=\"font:bold 16px Helvetica,Arial,sans-serif\"><a target=\"_blank\" href=\"%@\">%@</a></h1> \n"
"<br> \n"
"<table align=\"center\"> \n"
"<tbody> \n"
"<tr> \n"
"<td valign=\"top\" align=\"center\"> \n"
"<span style=\"font-family:Helvetica,Arial;font-size:11px;color:#696969;font-weight:bold\"> \n"
"</td> \n"
"</tr> \n"
"<tr> \n"
"<td align=\"left\"> \n"
"<span style=\"font-family:Helvetica,Arial;font-size:11px;color:#696969\"> \n"
"Please note that you have not been added to any email lists. \n"
"</span> \n"
"</td> \n"
"</tr> \n"
"</tbody> \n"
"</table> \n"
"</div>",
self.message,
[self.appStoreURL absoluteString],
self.applicationName
];
return emailBody;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.