从我的iPhone应用程序中把照片附在电子邮件中[英] Attach a photo to an email from my iPhone application

本文是小编为大家收集整理的关于从我的iPhone应用程序中把照片附在电子邮件中的处理方法,想解了从我的iPhone应用程序中把照片附在电子邮件中的问题怎么解决?从我的iPhone应用程序中把照片附在电子邮件中问题的解决办法?那么可以参考本文帮助大家快速定位并解决问题。

问题描述

我有一个 iPhone 应用程序,它从 App 内置的相册中挑选照片.现在我想添加一个分享按钮,可以选择通过电子邮件分享这张照片,我可以通过这个代码附加一张现有的照片:

    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@""];


// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@""]; 
[picker setToRecipients:toRecipients];


// Attach an image to the email
NSString *path = [[NSBundle mainBundle] pathForResource:@"project existing photo" ofType:@"jpg"];
NSData *myData = [NSData dataWithContentsOfFile:path];
[picker addAttachmentData:myData mimeType:@"image/jpeg" fileName:@"photo name"];

// Fill out the email body text
NSString *emailBody = @"";
[picker setMessageBody:emailBody isHTML:NO];

[self presentModalViewController:picker animated:YES];
[picker release];

但是我需要在此代码中进行哪些更改才能将选择的相册附加到电子邮件正文中?提前致谢.

推荐答案

使用 UIImagePickerController 允许用户选择图像.然后它会调用这个委托方法.

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    UIImage* image = [info objectForKey:UIImagePickerControllerOriginalImage];
    NSData* data = UIImageJPEGRepresentation(image, 1.0);
    // Your e-mail code here
}

本文地址:https://www.itbaoku.cn/post/924572.html