可能重复:
how to send email using UIbarbuttonitem without using MFMailComposerViewController
如图所示,此应用程序用于通过发送按钮的点击发送邮件。
我发现它没有显示MFMailComposerViewController。
怎么可能?我如何获得此功能?
答案 0 :(得分:1)
- (void)MailButton:(id)sender
{
if ([MFMailComposeViewController canSendMail]) {
//atableView.scrollEnabled=YES;
//[socailNetworkView removeFromSuperview];
// self.navigationItem.title = @"Contents";
MFMailComposeViewController *mailViewController = [[MFMailComposeViewController alloc] init];
mailViewController.mailComposeDelegate = self;
[mailViewController setSubject:@""];
[mailViewController setMessageBody:@"" isHTML:NO];
NSString *string = [NSString stringWithFormat:@"", nil];
NSArray *mailArr = [[NSArray alloc] initWithObjects:string,nil];
[mailViewController setToRecipients:mailArr];
[self presentModalViewController:mailViewController animated:YES];
[mailViewController release];
}
else {
NSLog(@"Device is unable to send email in its current state");
}
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error;
{
NSLog(@"Mail");
NSString *str=@"";
switch (result) {
case MFMailComposeResultCancelled:
NSLog(@"Mail send canceled.");
str=@"\nMail sending cancelled";
//msgLabel.text=str;
// [msgLabel setFont:[UIFont fontWithName:@"Arial" size:18]];
// msgLabel.textColor=[UIColor colorWithRed:(54.0/255.0) green:(2.0/255) blue:(1.0/255) alpha:1.0];
/*
Execute your code for canceled event here ...
*/
break;
case MFMailComposeResultSaved:
NSLog(@"Mail saved.");
str=@"Mail saved";
/*
Execute your code for email saved event here ...
*/
break;
case MFMailComposeResultSent:
NSLog(@"Mail sent.");
str=@"Mail sent";
/*
Execute your code for email sent event here ...
*/
break;
case MFMailComposeResultFailed:
str=@"Mail not sent";
NSLog(@"Mail send error: %@.", [error localizedDescription]);
/*
Execute your code for email send failed event here ...
*/
break;
default:
break;
}
//alertLabel.text=str;
// [viewAlert setBackgroundColor:[UIColor clearColor]];
// [self.view addSubview:viewAlert];
[self dismissModalViewControllerAnimated:YES];
}
答案 1 :(得分:1)
听起来你需要仔细阅读教程。
我是通过Google找到的:
New In iPhone 3.0 Tutorial Series, Part 2: In App Email, MessageUI
是的,它说的是“iPhone 3.0”,但相同的概念和代码应该在iOS 5中完美运行。