iOS menghantar e-mel
Hantar E-mel untuk IOS
Pengenalan
Kami boleh menghantar e-mel menggunakan aplikasi e-mel dalam peranti IOS.
Langkah instance
1 Cipta aplikasi berasaskan Paparan
2 Pilih fail projek, kemudian pilih sasaran, dan kemudian tambahkan MessageUI.framework
3 (tindakan)
4. Kemas kini ViewController.h seperti yang ditunjukkan di bawah
#import <UIKit/UIKit.h>#import <MessageUI/MessageUI.h>@interface ViewController : UIViewController<MFMailComposeViewControllerDelegate>{ MFMailComposeViewController *mailComposer;}-(IBAction)sendMail:(id)sender;@end
5 Kemas kini ViewController.m seperti yang ditunjukkan di bawah
#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
Output
Apabila menjalankan aplikasi, anda akan melihat output berikut
anda
klik butang "hantar e-mel", anda boleh melihat keputusan berikut: