Iphone iOS 5的MFMailComposeViewController:教程还是示例
有没有人有过关于如何通过编程或使用segues实现iOS5 mail composer的不错的教程?我在网上找到的大多数教程都来自旧的iOS版本。谢谢 您可以这样做:Iphone iOS 5的MFMailComposeViewController:教程还是示例,iphone,ios,ios5,Iphone,Ios,Ios5,有没有人有过关于如何通过编程或使用segues实现iOS5 mail composer的不错的教程?我在网上找到的大多数教程都来自旧的iOS版本。谢谢 您可以这样做: if([MFMailComposeViewController canSendMail]) { MFMailComposeViewController *mailController = [[MFMailComposeViewController alloc] init]; [mailController setM
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.");
首先,您必须将“MFMailComposeViewControllerDelegate”添加到接口部分
此外,您还必须添加过程,以便在用户点击“发送按钮”后获得响应
其实施变化不大。它只是创建视图控制器,并在最简单的情况下以模态方式调用它。基本上就像你不使用iOS情节串连板就可以按部就班地推送控制器一样。在做这件事之前,你必须检查[MFMailComposeViewController canSendMail],否则如果邮件没有设置,你会崩溃
- (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];
}