本文主要是介绍[IOS]调用手机邮件系统发送邮件,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
[IOS]调用手机邮件系统发送邮件
Demo:http://download.csdn.net/detail/u012881779/8819389
首先需要添加框架:MessageUI.framework
并且在真机或模拟器上添加自己邮箱
调用邮件系统:
- (IBAction)feedbackAction:(id)sender {[[GMMailObjc shareInstance] popMeailViewController];
}
功能实现:
#import <Foundation/Foundation.h>
#import <MessageUI/MessageUI.h>@interface GMMailObjc : NSObject<MFMailComposeViewControllerDelegate>+(instancetype) shareInstance;-(void) popMeailViewController;@end#import "GMMailObjc.h"
#import "AppDelegate.h"@implementation GMMailObjc+(instancetype) shareInstance{static dispatch_once_t onceToken ;dispatch_once(&onceToken, ^{_instance = [[self alloc] init] ;}) ;return _instance ;
}-(void)popMeailViewController{if([MFMailComposeViewController canSendMail]){MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];mc.mailComposeDelegate = self;//设置主收件人[mc setToRecipients:[NSArray arrayWithObjects:@"xxxxxx@qq.com", nil]];//主题[mc setSubject:@"意见反馈"];//信息[mc setMessageBody:@"\n\n我觉得非常好用,要是功能给更全,增加生活方面的小功能,对我们来说会更完美!" isHTML:NO];AppDelegate* APP = (AppDelegate *)[[UIApplication sharedApplication] delegate];UIViewController *objVC = [[APP.nav viewControllers]lastObject];[objVC presentViewController:mc animated:YES completion:nil];}else{//需先在真机或模拟器上添加自己的邮箱UIAlertView* alert = [[UIAlertView alloc] initWithTitle:nil message:@"请先配置邮箱账号!" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];[alert show];}
}- (void)mailComposeController:(MFMailComposeViewController*)controllerdidFinishWithResult:(MFMailComposeResult)resulterror:(NSError*)error {switch (result){case MFMailComposeResultCancelled:NSLog(@"Mail send canceled...");break;case MFMailComposeResultSaved:NSLog(@"Mail saved...");break;case MFMailComposeResultSent:NSLog(@"Mail sent...");break;case MFMailComposeResultFailed:NSLog(@"Mail send errored: %@...", [error localizedDescription]);break;default:break;}AppDelegate* APP = (AppDelegate *)[[UIApplication sharedApplication] delegate];UIViewController *objVC = [[APP.nav viewControllers]lastObject];[objVC dismissViewControllerAnimated:YES completion:nil];
}@end
示意图:
这篇关于[IOS]调用手机邮件系统发送邮件的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!