- (void) sendEmail {
if (![MFMailComposeViewController canSendMail]) {
HBAlert(@"Can't send email", @"Sorry, your device is not able to send email");
return;
}
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
[mailer setMailComposeDelegate:self];
NSString *subject = @"Whatever subject;
[mailer setSubject:subject];
NSString *body = @"This is a test email from my app.";
[mailer setMessageBody:body isHTML:NO];
[mailer setModalPresentationStyle:UIModalPresentationFormSheet];
[self presentViewController:mailer animated:YES completion:nil];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
switch (result) {
case MFMailComposeResultCancelled:
NSLog(@"Mail cancelled");
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved as draft");
break;
case MFMailComposeResultSent:
NSLog(@"Mail is sent");
break;
case MFMailComposeResultFailed:
NSLog(@"Sending mail failed");
break;
default:
break;
}
[self dismissViewControllerAnimated:YES completion:nil];
}
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.