- (void)openMail {
NSString *mail = @"support@126.com";
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init];
[mailCompose setToRecipients:@[mail]]; //设置收件人
mailCompose.mailComposeDelegate = self;
[self presentViewController:mailCompose animated:YES completion:nil];
} else {
// 用户没有设置邮箱账号
NSString *str = [NSString stringWithFormat:@"mailto:%@", mail];
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
}
}
}
#pragma mark - MFMailComposeViewControllerDelegate
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[controller dismissViewControllerAnimated:YES completion:nil];
}