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

查看:128
本文介绍了将照片附加到我的iPhone应用程序的电子邮件中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have an iPhone application that picks a photos from the photo album built in App. Now I want to add a sharing button with an option of sharing this photo by email , I can attach an existing photo through this code :

    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];

但是我需要在此代码中更改以将选定的相册附加到电子邮件正文中?
提前致谢。

But what do I need to change in this code to attach the picked photo album into the email body ? Thanks in advance.

推荐答案

使用 UIImagePickerController 允许用户选择图像。然后它将调用此委托方法。

Use UIImagePickerController to allow the user to pick an image. It will then call this delegate method.

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

这篇关于将照片附加到我的iPhone应用程序的电子邮件中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆