-(IBAction)sendEmail{ MFMailComposeVIEwController *composer = [[MFMailComposeVIEwController alloc] init]; [composer setMailComposeDelegate:self]; if ([MFMailComposeVIEwController canSendMail]) { [composer setToRecipIEnts:[NSArray arrayWithObjects:@"FrankMurphy.CEO@RomansXIII.com",nil]]; [composer setModalTransitionStyle:UIModalTransitionStyleCrossdissolve]; [self presentVIEwController:composer animated:YES]; } } -(voID)mailComposeController:(MFMailComposeVIEwController *)controller dIDFinishWithResult:(MFMailComposeResult)result error:(NSError *)error { if(error) { UIAlertVIEw *alert = [[UIAlertVIEw alloc] initWithTitle:@"error" message:[Nsstring stringWithFormat:@"error %@",[error description]] delegate:nil cancelbuttonTitle:@"dismiss" otherbuttonTitles:nil,nil]; [alert show]; [self dismissVIEwControllerAnimated:YES]; } else { [self dismissVIEwControllerAnimated:YES]; } }解决方法 在.h头文件….
#import <UIKit/UIKit.h>#import <MessageUI/MessageUI.h>@interface SimpleEmailVIEwController : UIVIEwController <MFMailComposeVIEwControllerDelegate> // Add the delegate- (IBAction)showEmail:(ID)sender;@end
在.m实现文件中…..
- (IBAction)showEmail:(ID)sender {// Email SubjectNsstring *emailTitle = @"Test Email";// Email ContentNsstring *messageBody = @"iOS programming is so fun!";// To addressNSArray *toRecipents = [NSArray arrayWithObject:@"info@finetechnosoft.in"];MFMailComposeVIEwController *mc = [[MFMailComposeVIEwController alloc] init];mc.mailComposeDelegate = self;[mc setSubject:emailTitle];[mc setMessageBody:messageBody isHTML:NO];[mc setToRecipIEnts:toRecipents];// Present mail vIEw controller on screen[self presentVIEwController:mc animated:YES completion:NulL];}- (voID) mailComposeController:(MFMailComposeVIEwController *)controller dIDFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{switch (result){ case MFMailComposeResultCancelled: NSLog(@"Mail cancelled"); break; case MFMailComposeResultSaved: NSLog(@"Mail saved"); break; case MFMailComposeResultSent: NSLog(@"Mail sent"); break; case MFMailComposeResultFailed: NSLog(@"Mail sent failure: %@",[error localizedDescription]); break; default: break;}// Close the Mail Interface[self dismissVIEwControllerAnimated:YES completion:NulL];}总结
以上是内存溢出为你收集整理的ios – 如何在Xcode中的应用程序内发送电子邮件?全部内容,希望文章能够帮你解决ios – 如何在Xcode中的应用程序内发送电子邮件?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)