我该如何通过程序显示邮件设置页面?
在我的应用中,我为用户提供了反馈选项。当点击反馈按钮时,我会检查设备中是否有任何可用的邮件帐户。这是通过以下检查完成的:
if ([MFMailComposeViewController canSendMail])
{
// Actions to send mail
}
else
{
//Actions to show an error message by UIAlertView
}
警告消息将会是这样的:
![无邮件账号警告](https://istack.dev59.com/L6Szp.webp)
![邮件设置页面](https://istack.dev59.com/VOX2W.webp)
我该如何通过程序显示邮件设置页面?
在我的应用中,我为用户提供了反馈选项。当点击反馈按钮时,我会检查设备中是否有任何可用的邮件帐户。这是通过以下检查完成的:
if ([MFMailComposeViewController canSendMail])
{
// Actions to send mail
}
else
{
//Actions to show an error message by UIAlertView
}
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: @"mailto:test@test.com"]];
这将打开本机邮件应用程序主页,允许用户添加新的邮件帐户。
希望对您有所帮助 :)
MFMailComposeViewController
类和MFMailComposeViewControllerDelegate
协议,首先发送一条消息:
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setSubject:@"My Subject"];
[controller setMessageBody:@"Hello there." isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error;
{
if (result == MFMailComposeResultSent) {
NSLog(@"It's away!");
}
[self dismissModalViewControllerAnimated:YES];
}
#import <MessageUI/MessageUI.h>
#import <MessageUI/MFMailComposeViewController.h>
add <MFMailComposeViewControllerDelegate> like
@interface ManageRequestViewController : UIViewController<MFMailComposeViewControllerDelegate>
in .m file
if([MFMailComposeViewController canSendMail]){
MFMailComposeViewController *mail=[[MFMailComposeViewController alloc]init];
mail.mailComposeDelegate=self;
[mail setSubject:@"your subject"];
[mail setMessageBody:@"mail!" isHTML:NO];
[self presentModalViewController:mail animated:YES];
[mail release];
}
- (void)mailComposeController:(MFMailComposeViewController*)mailController didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[self dismissModalViewControllerAnimated:YES];
}
对于你的具体问题,简短的回答是:无法使用 iOS SDK 编程实现邮件帐户的创建。
无法完成。即使有一个启动设置应用程序的接口(我不知道是否有),也没有办法指定要转到该应用程序的哪个屏幕。这不像网站,每个页面都有一个URL。
-(IBAction)showPicker:(id)sender {
-(IBAction)显示选择器:(id)发送者 {
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
//mail not config
}
}