首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS 5的MFMailComposeViewController :教程或示例

iOS 5的MFMailComposeViewController :教程或示例
EN

Stack Overflow用户
提问于 2012-09-13 03:24:34
回答 2查看 2.4K关注 0票数 0

有没有人有一个很好的教程,教你如何在iOS5上通过编程或segues实现mail composer?我在网上找到的大多数教程都来自旧的iOS版本。谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-09-13 04:38:20

你可以这样做:

代码语言:javascript
运行
复制
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.");
票数 5
EN

Stack Overflow用户

发布于 2015-05-11 20:47:43

首先,您必须将"MFMailComposeViewControllerDelegate“添加到接口部分。

此外,您还必须添加程序,以获得响应后,用户点击“发送按钮”

代码语言:javascript
运行
复制
- (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];

}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12394928

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档