[英]Add photo to MFMailComposeViewDelegate ( Xcode 4.2, iOS 5, ARC, LLDB, Storyboard, Universal App )
我已经在互联网上搜索和搜索过,但是还没有找到适合我情况的正确答案。 (Xcode 4.2,iOS 5,ARC,LLDB,Storyboard,Universal App)
寻找允许用户选择要添加到电子邮件中的照片的方法。
我想使其不显眼,并在MFMailComposeViewController中添加一个按钮,该按钮允许用户从其照片库添加照片或使用其相机拍摄照片。
我试图在UIController上使用UIImpagePicker和Camera的viewController按钮,通过单独的邮件功能按钮将图像添加到UIImageView,但这太过分了,不必要地使应用程序混乱,我也无法弄清楚要插入的代码选择的照片放入电子邮件。
我的inapp电子邮件运行正常,这是代码
。H
#import <MessageUI/MessageUI>
<MFMailComposeViewControllerDelegate>
.m
- (IBAction)Email:(id)sender
{
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init];
mail.mailComposeDelegate = self;
[mail setSubject:@"Feedback"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"feedback", nil];
[mail setToRecipients:toRecipients];
NSString *emailBody = @"-Your Message Here-";
[mail setMessageBody:emailBody isHTML:NO];
mail.modalPresentationStyle = UIModalPresentationPageSheet;
[self presentModalViewController:mail animated:YES];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error:"
message:@"E-mail is not supported on your device."
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:nil];
[alert show];
}
}
邮件编辑器不提供自己添加用户选择的照片的功能,并且不建议将控件添加到编辑器视图控制器中。
您必须先让用户使用UIImagePickerController选择照片,然后在提供邮件编辑器时将其添加为附件。
问题不是如何编码,而是如何设计UI。 也许您可以使它有点像twitter应用程序处理各种附件和其他信息。
法比安
但您无法访问照片库文件或所选文件的目录以作为附件添加到邮件选择器。
它必须像:
NSString * path = [[[NSBundle mainBundle] pathForResource:@“ arrest” ofType:@“ png”]; NSData * myData = [NSData dataWithContentsOfFile:path]; [picker addAttachmentData:myData mimeType:@“ image / png” fileName:@“ arrest”];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.