gpt4 book ai didi

ios - 如何从我的自定义 UIActivity 类发送电子邮件?

转载 作者:行者123 更新时间:2023-11-29 13:05:13 27 4
gpt4 key购买 nike

我制作了一个服装 UIActivity 类。我喜欢在类里面发送带有附件的电子邮件,但我无法发送电子邮件,也无法展示类里面的任何 ViewController。我试图用这个来呈现 Mail ViewController:

- (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?

我使用了这个代码:How can I create a custom UIActivity in iOS?

最佳答案

抱歉,我现在才回答这个问题(我知道很久以前有人问过这个问题)但这是我的回答:

#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

关于ios - 如何从我的自定义 UIActivity 类发送电子邮件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18810822/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com