Reputation: 3361
I am new to this,
I have this code in my viewController,
- (void)sendMail:(id)sender {
NSArray *to = [NSArray arrayWithObjects:@"[email protected]", nil];
mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:to];
[mailComposer setSubject:@"Test Mail"];
[mailComposer setMessageBody:@"Testing message body" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
}
#pragma mark - mail compose delegate
-(void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
if(result) {
NSLog(@"Result = %d", result);
}
if(error) {
NSLog(@"Error = %@", error);
}
[self dismissModalViewControllerAnimated:YES];
}
But when I click send button in my controller, I am getting error like,
2016-09-05 14:55:24.488 mailDemo[1276:104171] viewServiceDidTerminateWithError: Error Domain=_UIViewServiceInterfaceErrorDomain Code=3 "(null)" UserInfo={Message=Service Connection Interrupted} 2016-09-05 14:55:24.989 mailDemo[1276:104171] Trying to dismiss the presentation controller while transitioning already. (<_UIFullscreenPresentationController: 0x7fe35b52d2a0>) 2016-09-05 14:55:24.991 mailDemo[1276:104171] transitionViewForCurrentTransition is not set, presentation controller was dismissed during the presentation? (<_UIFullscreenPresentationController: 0x7fe35b52d2a0>)
What is the issue?
Upvotes: 3
Views: 209
Reputation: 97
MFMailComposeViewController does not work for simulators. If you try the same code in real device, it will work. There is nothing wrong with your code.
Upvotes: 0
Reputation: 3244
simulator doesn't supported method and device doesn't login in mail that this method nothing response.
replace this method ::
- (void)sendMail:(id)sender {
if (![MFMailComposeViewController canSendMail]) {
NSLog(@"Mail services are not available.");
return;
}
else{
NSArray *to = [NSArray arrayWithObjects:@"[email protected]", nil];
mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setToRecipients:to];
[mailComposer setSubject:@"Test Mail"];
[mailComposer setMessageBody:@"Testing message body" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
}
}
Upvotes: 1
Reputation: 2298
There is nothing wrong with your code.MFMailComposeViewController
is not work for simulator, Try same code in real device.
Upvotes: 2