0
我試圖設置從我的應用程序中發送電子郵件的能力。我的應用程序是基於其使用對象來運行它的所有UI的SpeakHere示例項目:如何我需要設置MFMailComposeViewControllerDelegate 實現MFMailComposeViewControllerDelegate並將其添加到您的視圖控制器
這使得對我來說這很混亂,等等
這有點延伸my previous question。
任何幫助?
我試圖設置從我的應用程序中發送電子郵件的能力。我的應用程序是基於其使用對象來運行它的所有UI的SpeakHere示例項目:如何我需要設置MFMailComposeViewControllerDelegate 實現MFMailComposeViewControllerDelegate並將其添加到您的視圖控制器
這使得對我來說這很混亂,等等
這有點延伸my previous question。
任何幫助?
我解決了使用this example code.
完整的示例代碼,這個問題:
- (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];
}