How to programmatically display the mail setup page on an iPhone?

How to show the mail setup page programmatically?

In my application, I offered the user the possibility of feedback. By selecting the feedback button, I check if there is any mail account on the device or not. This is done with the following check:

if ([MFMailComposeViewController canSendMail]) { // Actions to send mail } else { //Actions to show an error message by UIAlertView } 

A warning message will look like this:

No mail account alert

If the user clicked OK in this UIAlertView , I want to go to the mail settings page available in the settings menu. That is, I want to show the following page:

mail setup page

Is it possible to make this navigation programmatically?

+6
source share
6 answers

When the user clicks the OK warning button, use the code below.

 [[UIApplication sharedApplication] openURL: [NSURL URLWithString: @"mailto: test@test.com "]]; 

This will open the home page of the native Mail application, allowing the user to add a new account.

Hope this helps :)

+5
source

You should use the class MFMailComposeViewController and MFMailComposeViewControllerDelegate .

PeyloW provides the following code for this in his answer here :

First send a message:

 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]; 

Then the user does the work, and you get the delegate callback in time:

 - (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error; { if (result == MFMailComposeResultSent) { NSLog(@"It away!"); } [self dismissModalViewControllerAnimated:YES]; } 
+2
source

Add a messageUI framework. in .h file

 #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]; } 
0
source

The short answer to your specific question is that it is not possible to programmatically enable the creation of an email account using the iOS SDK.

0
source

Unable to execute. Even if there is an interface for launching the Settings application (which I don’t know if it exists), there is no way to indicate which screen of this application should be accessed. This is not like a website where each page has a URL.

0
source

- (IBAction) showPicker: (identifier) ​​of sender {

  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 } } 
0
source

Source: https://habr.com/ru/post/888198/


All Articles