1. - (void)openMail {
    2. NSString *mail = @"support@126.com";
    3. if ([MFMailComposeViewController canSendMail]) {
    4. MFMailComposeViewController *mailCompose = [[MFMailComposeViewController alloc] init];
    5. [mailCompose setToRecipients:@[mail]]; //设置收件人
    6. mailCompose.mailComposeDelegate = self;
    7. [self presentViewController:mailCompose animated:YES completion:nil];
    8. } else {
    9. // 用户没有设置邮箱账号
    10. NSString *str = [NSString stringWithFormat:@"mailto:%@", mail];
    11. NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]]];
    12. if ([[UIApplication sharedApplication] canOpenURL:url]) {
    13. [[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
    14. }
    15. }
    16. }
    17. #pragma mark - MFMailComposeViewControllerDelegate
    18. - (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
    19. [controller dismissViewControllerAnimated:YES completion:nil];
    20. }