iOS调起系统邮箱

来源:互联网 发布:mac迅雷 编辑:程序博客网 时间:2024/05/16 00:33

调起系统邮箱

1.引入MessageUI.framework框架
2.添加头文件
#import <MessageUI/MFMailComposeViewController.h>

具体代码片段

-(void)openSystemEmail{    // Email Content    //c方法,填写系统结构体内容,返回值为0,表示成功。    NSString *messageBody = [NSString stringWithFormat:@"Model:%@\n%@\nApp: %@\nFeedback here:\n",[[UIDevice currentDevice] systemVersion],[SystemSetting getDeviceModel], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]];    // To address    NSArray *toRecipents = [NSArray arrayWithObject:@"your emails "];    MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];    mc.mailComposeDelegate = self;    [mc setSubject:@"我的建议"];//邮件主题    [mc setMessageBody:messageBody isHTML:NO];//邮件部分内容    [mc setToRecipients:toRecipents];//发送地址    [mc.navigationBar setTintColor:[UIColor whiteColor]];    // Present mail view controller on screen    if (!mc) {        return;    }else{        [self presentViewController:mc animated:YES completion:NULL];    }}
#pragma mark 调起系统邮箱的代理方法- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error{    NSString*message;    switch (result)    {        case MFMailComposeResultCancelled:            NSLog(@"Mail cancelled");            //message=[NSString stringWithFormat:@"%@",@"Mail cancelled"];            break;        case MFMailComposeResultSaved:            NSLog(@"Mail saved");            // message=[NSString stringWithFormat:@"%@",@"Mail saved"];            break;        case MFMailComposeResultSent:            NSLog(@"Mail sent");            // message=[NSString stringWithFormat:@"%@",@"Mail sent"];            break;        case MFMailComposeResultFailed:            NSLog(@"Mail sent failure: %@", [error localizedDescription]);            message=[NSString stringWithFormat:@"%@",[error localizedDescription]];            [[[UIAlertView alloc]initWithTitle:@"提示" message:message delegate:self cancelButtonTitle:nil otherButtonTitles:@"确定", nil] show ];            break;        default:            break;    }    [self dismissViewControllerAnimated:YES completion:NULL];}
0 0
原创粉丝点击