0

有没有人有关于如何以编程方式或使用 segues 为 ios 5 实现邮件编写器的不错的教程?我在网上找到的大多数教程都来自旧的 iOS 版本。谢谢!

4

2 回答 2

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.");
于 2012-09-12T20:38:20.110 回答
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];

}
于 2015-05-11T12:47:43.007 回答