我是 iOS 的新手,正在尝试在我的应用程序中添加不恰当的电子邮件。我有一个屏幕,在其中按下电子邮件图标应该会打开 inapp 电子邮件。我有 inapp 电子邮件的代码。但是,按钮已经是 Controller 上的 socket 。所以,我不知道如何将同一个按钮链接到具有 inapp 电子邮件代码的不同类/文件。我正在考虑设置一个委托(delegate),但不知道如何在邮件类中初始化委托(delegate)。已经苦苦挣扎了几天...请帮忙!
提交
最佳答案
试试 MFMailComposeViewController.... 下面是一些示例代码: 确保导入 MEssageUI 框架并在 .h 中导入 MFMailComposeViewController/MessageUI 并符合其委托(delegate)
MFMailComposeViewController *mailView = [[MFMailComposeViewController alloc] init];
[mailView setMailComposeDelegate:self];
if ([MFMailComposeViewController canSendMail]) {
[mailView setSubject:@"Interesting Apple News Article!"];
NSString *mailString = [[NSString alloc] initWithFormat:@"Test!"];
[mailView setMessageBody:mailString isHTML:NO];
[mailView setModalTransitionStyle:UIModalTransitionStyleCoverVertical];
[self presentModalViewController:mailView animated:YES];
[mailString release];
[mailView release];
} else
[mailView release];
}
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if (error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Mailing Error" message:[error localizedDescription] delegate:self cancelButtonTitle:@"Dismiss" otherButtonTitles:nil, nil];
[alert show];
[alert release];
[self dismissModalViewControllerAnimated:YES];
} else {
[self dismissModalViewControllerAnimated:YES];
}
}
关于ios - 在 ios 中与 inapp 电子邮件作斗争,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10393264/