有没有人有关于如何以编程方式或使用segues为ios 5实现邮件编辑器的体面教程?我在网上找到的大多数教程都来自旧的iOS版本。谢谢!
答案 0 :(得分:5)
你可以这样做:
if([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init];
[mailController setMailComposeDelegate:self];
[mailController setSubject:@"Mail Subject!"];
[mailController setMessageBody:@"Here is your message body" isHTML:NO];
[mailController setToRecipients:[NSArray arrayWithObject:@"yourrecipent@domain.com"]];
NSData *imageData = UIImageJPEGRepresentation(imageToUpload, 1.0f);
if(imageData.length)
{
[mailController addAttachmentData:imageData mimeType:@"image/jpeg" fileName:@"Your_Photo.jpg"];
[self presentModalViewController:mailController animated:YES];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Image" message:@"The image couldn't be converted." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
[alert show];
}
}
else NSLog(@"Hah. No mail for you.");
答案 1 :(得分:2)
首先你需要添加" MFMailComposeViewControllerDelegate"接口部分。
此外,您必须添加程序以在用户点击后发出响应"发送按钮"
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
switch (result) {
case MFMailComposeResultSent:
NSLog(@"You sent the email.");
break;
case MFMailComposeResultSaved:
NSLog(@"You saved a draft of this email");
break;
case MFMailComposeResultCancelled:
NSLog(@"You cancelled sending this email.");
break;
case MFMailComposeResultFailed:
NSLog(@"Mail failed: An error occurred when trying to compose this email");
break;
default:
NSLog(@"An error occurred when trying to compose this email");
break;
}
[self dismissViewControllerAnimated:YES completion:NULL];
}