如何从自定义UIActivity类发送电子邮件? [英] How can I send emails from my custom UIActivity class?
本文介绍了如何从自定义UIActivity类发送电子邮件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我制作了一个服装UIActivity类.我喜欢发送带有附件的电子邮件,但不能发送电子邮件,也不能显示该类中的任何ViewController.我正在尝试为此提供邮件ViewController:
I made a costume UIActivity class. I like to send emails with attachments with the class, but I can't send emails, or present any ViewControllers from the class. I am trying to present the Mail ViewController with this:
- (void)prepareWithActivityItems:(NSArray *)activityItems
{
NSString *subject = [NSString stringWithFormat:@"%@", [self.filePath lastPathComponent]];
NSString *messageBody = [NSString stringWithFormat:@"%@ was extracted with @FilyForiOS, visit", [self.filePath lastPathComponent]];
NSData *attachment = [NSData dataWithContentsOfFile:self.filePath];
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
mc.mailComposeDelegate = self;
[mc setSubject:subject];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:nil];
[mc addAttachmentData:attachment mimeType:[[self.filePath lastPathComponent] pathExtension] fileName:[self.filePath lastPathComponent]];
[self presentViewController:mc animated:YES completion:nil]; // Here is the error: No visible @interface for 'MailTo' declares the selector 'presentViewController:animated:completion:'
}
有人可以告诉我如何从此类中提出一个ViewController吗?
Can anyone tell me how I can present a ViewController from this class?
我使用了以下代码:如何创建iOS中的自定义UIActivity?
推荐答案
很抱歉,我现在正在回答这个问题(我知道这是在很久以前提出的),但这是我的答案:
Sorry that I'm just now answering this (I know this was asked along time ago) But here is my answer:
#import <MessageUI/MessageUI.h>
@interface EmailActivity : UIActivity <MFMailComposeViewControllerDelegate>
@end
@implementation EmailActivity
- (NSString *)activityTitle
{
// Your title
return @"Email";
}
- (UIImage *)activityImage
{
// Your image
return [UIImage imageNamed:@"Email"];
}
- (BOOL)canPerformWithActivityItems:(NSArray *)activityItems
{
return YES;
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
[self activityDidFinish:YES];
}
- (UIViewController *)activityViewController
{
MFMailComposeViewController *mc = [[MFMailComposeViewController alloc]init];
if ([MFMailComposeViewController canSendMail])
{
NSString *subject = [NSString stringWithFormat:@"%@", [self.filePath lastPathComponent]];
NSString *messageBody = [NSString stringWithFormat:@"%@ was extracted with @FilyForiOS, visit", [self.filePath lastPathComponent]];
NSData *attachment = [NSData dataWithContentsOfFile:self.filePath];
[mc setSubject:subject];
[mc setMessageBody:messageBody isHTML:NO];
[mc setToRecipients:nil];
[mc addAttachmentData:attachment mimeType:[[self.filePath lastPathComponent] pathExtension] fileName:[self.filePath lastPathComponent]];
mc.mailComposeDelegate = self;
return mc;
}
else
{
return nil;
}
}
@end
这篇关于如何从自定义UIActivity类发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文