2011-04-22 30 views

回答

0

完整的示例代碼,這個問題:

- (IBAction)email:(id)sender { 
    if ([MFMailComposeViewController canSendMail]){ 

     MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init]; 
     mail.mailComposeDelegate = self; 
     [mail setSubject:@"Sample Subject"]; 
     [mail setMessageBody:@"Here is some main text in the email!" isHTML:NO]; 
     [mail setToRecipients:@[@"[email protected]"]]; 

     [self presentViewController:mail animated:YES completion:NULL]; 
    }else { 
     NSLog(@"This device cannot send email"); 
    } 
} 

#pragma mark - MFMailComposeViewControllerDelegate 

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { 

    switch (result) { 
     case MFMailComposeResultSent: 
      NSLog(@"You sent the email."); 
      break; 
     case MFMailComposeResultSaved: 
      NSLog(@"You saved a draft of this email"); 
      break; 
     case MFMailComposeResultCancelled: 
      NSLog(@"You cancelled sending this email."); 
      break; 
     case MFMailComposeResultFailed: 
      NSLog(@"Mail failed: An error occurred when trying to compose this email"); 
      break; 
     default: 
      NSLog(@"An error occurred when trying to compose this email"); 
      break; 
    } 

    [self dismissViewControllerAnimated:YES completion:NULL]; 
} 
相關問題