IOS發送電子郵件
簡介
我們可以使用(yòng)IOS設備中的電子郵件應用(yòng)程序發送電子郵件。
實例步驟
1、創建一個簡單的View based application
2、選擇項目文(wén)件,然後選擇目标,然後添加MessageUI.framework
3、在ViewController.xib中添加一個按鈕,創建用(yòng)于發送電子郵件的操作(zuò)(action)
4、更新ViewController.h,如下(xià)所示
#import
#import
@interface ViewController : UIViewController
{
MFMailComposeViewController *mailComposer;
}
-(IBAction)sendMail:(id)sender;
@end
5、如下(xià)所示,更新ViewController.m
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)sendMail:(id)sender{
mailComposer = [[MFMailComposeViewController alloc]init];
mailComposer.mailComposeDelegate = self;
[mailComposer setSubject:@"Test mail"];
[mailComposer setMessageBody:@"Testing message
for the test mail" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
}
#pragma mark - mail compose delegate
-(void)mailComposeController:(MFMailComposeViewController *)controller
didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error{
if (result) {
NSLog(@"Result : %d",result);
}
if (error) {
NSLog(@"Error : %@",error);
}
[self dismissModalViewControllerAnimated:YES];
}
@end
網站(zhàn)建設開(kāi)發|APP設計(jì)開(kāi)發|小(xiǎo)程序建設開(kāi)發