ios - 如何使用 MFMailComposerViewController 从自定义 UITableViewCell 发送邮件
问题描述
我想在单击自定义按钮时UITableViewCell
使用MFMailComposeViewController
.
感谢答案是否在 Objective-C 中。
解决方案
确保您是在真实设备中而不是在模拟器中测试它,并且您在设备中配置了邮件 ID
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
@interface ViewController ()<MFMailComposeViewControllerDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction)sendmail:(id)sender {
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:@"Subject"];
NSArray *toRecipients = [NSArray arrayWithObjects:@"Recipients", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody = @"Body";
[mailer setMessageBody:emailBody isHTML:NO];
[self presentViewController:mailer animated:YES completion:nil];
}
}
- (void) mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
// Close the Mail Interface
[self dismissViewControllerAnimated:NO completion:NULL];
}
推荐阅读
- python - 访问列表字典中列表的最小元素
- python - Mac M1 中损坏的 Python
- android - Android 上的 Expo 图像压缩
- angular - 在页面上添加相同 Angular 元素的两个实例会中断路由
- c# - 有没有办法根据向导中的用户输入从 Visual Studio 项目模板中排除文件?
- javascript - 服务器集成测试
- c# - 如何解决 INSERT 语句与 FOREIGN KEY 约束“FK_Tickets_AspNetUsers_UserId”冲突
- dataframe - 加载多个 xls 文件、编辑和附加到一个数据帧中
- javascript - 如何在 Javascript 中组合函数
- apache-spark - Spark 到 JDBC:Py4JJavaError - 连接已启动,但没有一个提供者