2012-11-09 96 views
0

我试图将图像附加到从应用程序发送的邮件图像 我不知道该怎么做,请在这里告知我的代码:从应用程序附加图像到电子邮件

 NSString * subject = @"Hello"; 
    NSString * address = @"[email protected]"; 

    NSMutableString *strBody=[[NSMutableString alloc]init]; 
    [strBody setString:_txtName.text]; 
    [strBody appendString:_txtIngredients.text]; 
    [strBody appendString:_txtPreper.text]; 
    [strBody appendString:_txtServe.text]; 
    [strBody appendString:_txtAboutdrink.text]; 
    [strBody appendString:_txtSource.text]; 

    //NSData *data = UIImagePNGRepresentation(_imgDrink);---- here is my problem 


    NSURL *url; 

    NSString * path = [NSString stringWithFormat:@"mailto:%@?subject=%@&body=%@", address, subject,strBody]; 
    url = [NSURL URLWithString:[path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

    [[UIApplication sharedApplication] openURL:url]; 
+0

查看此答案。应该帮助你 http://stackoverflow.com/questions/4302403/how-can-send-a-file-as-attachment-in-objective-c –

回答

0

如果您不介意显示一个表单供用户在电子邮件中输入消息,我建议您使用MFMailComposeViewController。通过这个,你可以很容易地添加附件。您还可以预先填充收件人和邮件正文以及有关电子邮件的其他所有内容。在你的工具包中有一个方便的类。

相关问题