新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
創(chuàng)新互聯(lián)IOS教程:iOS發(fā)送電子郵件
iOS發(fā)送電子郵件
簡(jiǎn)介
我們可以使用IOS設(shè)備中的電子郵件應(yīng)用程序發(fā)送電子郵件。

實(shí)例步驟
1、創(chuàng)建一個(gè)簡(jiǎn)單的View based application
2、選擇項(xiàng)目文件,然后選擇目標(biāo),然后添加MessageUI.framework
3、在ViewController.xib中添加一個(gè)按鈕,創(chuàng)建用于發(fā)送電子郵件的操作(action)
4、更新ViewController.h,如下所示
#import#import @interface ViewController : UIViewController { MFMailComposeViewController *mailComposer; } -(IBAction)sendMail:(id)sender; @end
5、如下所示,更新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
輸出
當(dāng)運(yùn)行該應(yīng)用程序,會(huì)看如下的輸出結(jié)果
當(dāng)點(diǎn)擊"send email"發(fā)送按鈕后,可以看到如下結(jié)果:
標(biāo)題名稱:創(chuàng)新互聯(lián)IOS教程:iOS發(fā)送電子郵件
URL鏈接:http://m.fisionsoft.com.cn/article/cohhphj.html


咨詢
建站咨詢
