将数据从视图控制器传递到 iOS 电子邮件应用程序



如果我错过了一些东西,请原谅我昨天才开始这个 iOS 开发。我有一个基本的应用程序,用户最多可以拍摄 3 张照片,这些图片保存在 3 个不同的 UIImageView 中,该应用程序还检索 GPS 坐标并将其更改为地址。

我想做的是能够将这些图像和信息发送到电子邮件地址。

目前我有一个链接到操作的发送按钮。

谢谢

- (IBAction)sendFinalItem:(UIButton *)sender {
    NSLog(@"send button pressed");
    MFMailComposeViewController *mailcontroller = [[MFMailComposeViewController alloc] init];
    [mailcontroller setMailComposeDelegate:self];
    NSString *email =@"MYEMAIL@MYEMAIL.CO.UK";
    NSArray *emailArray = [[NSArray alloc] initWithObjects:email, nil];
    [mailcontroller setToRecipients:emailArray];
    [mailcontroller setSubject:@"[Urgent]Potential Job, iPhone snapped"];
    [self presentViewController:mailcontroller animated:YES completion:nil];
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:         (MFMailComposeResult)result error:(NSError *)error
{
    switch (result)
     {
        case MFMailComposeResultCancelled:
         NSLog(@"Mail cancelled");
        break;
        case MFMailComposeResultSaved:
        NSLog(@"Mail saved");
        break;
        case MFMailComposeResultSent:
         NSLog(@"Mail sent");
        break;
        case MFMailComposeResultFailed:
         NSLog(@"Mail sent failure: %@", [error localizedDescription]);
        break;
        default:
       break;
     }
// Close the Mail Interface
[self dismissViewControllerAnimated:YES completion:NULL];
}

在你的sendFinalItem方法中写这个。

NSData *dataImage = UIImageJPEGRepresentation(yourImageViewName.image, 0.5f);
[mailer addAttachmentData:dataImage mimeType:@"image/jpeg" fileName:@"Image_1.jpg"]

希望这有帮助。

编辑:

[mailer setMessageBody:yourTextView.text isHTML:NO];

您可以将isHTML设置为 YES 。(如果您的textview包含 HTML 数据

编辑:

如果您想要高质量的图像,请使用UIImagePNGRepresentation(yourImageViewName.image)而不是UIImageJPEGRepresentation(yourImageViewName.image, 0.5f)

快乐编码..

最新更新