无法从 iPhone 应用程序发送邮件
@interface ViewController : UIViewController { //....yor variables }
在 ViewController.m 文件中:
(void)viewDidLoad {
[super viewDidLoad];
self.title = @"Sample Email Application"; // title of navigation bar
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(composeMail:)] autorelease]; // for adding a compose button //in navigation bar. //...your code }
-(void) composeMail: (id) sender{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTintColor:[UIColor blackColor]];
[picker setSubject:@"Sample Email Application"];
[picker setMessageBody:[NSString stringWithFormat:@"Visit for more help %@. ",@"http://google.com"] isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[controller dismissModalViewControllerAnimated:YES];
}
@interface ViewController : UIViewController { //....yor variables }
in ViewController.m file:
(void)viewDidLoad {
[super viewDidLoad];
self.title = @"Sample Email Application"; // title of navigation bar
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(composeMail:)] autorelease]; // for adding a compose button //in navigation bar. //...your code }
-(void) composeMail: (id) sender{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
picker.mailComposeDelegate = self;
[[picker navigationBar] setTintColor:[UIColor blackColor]];
[picker setSubject:@"Sample Email Application"];
[picker setMessageBody:[NSString stringWithFormat:@"Visit for more help %@. ",@"http://google.com"] isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error {
[controller dismissModalViewControllerAnimated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎缺少 -setToRecipients,除非您有要发送的地址,否则您无法发送邮件。
It looks like you are missing the -setToRecipients, which you can't send mail unless you have an address to send to.