iOS 之发送邮件的常用方法
来源:互联网 发布:淘宝旗舰店查真假 编辑:程序博客网 时间:2024/05/01 09:51
#pragma mark - email
- (void)showMailPicker
{
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil) {
if ([mailClass canSendMail]) {
[self displayMailComposerSheet];
}else{
[self launchMailAppOnDevice];
}
}else{
[self launchMailAppOnDevice];
}
}
- (void)displayMailComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
-(void)launchMailAppOnDevice
{
NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=my email!";
//@"mailto:support@shichangit.com?subject=意见与反馈"
NSString *body = @"&body=";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSString *msg;
switch (result)
{
case MFMailComposeResultCancelled:
msg = @"邮件发送取消";
break;
case MFMailComposeResultSaved:
msg = @"邮件保存成功";
[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultSent:
msg = @"邮件发送成功";
[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultFailed:
msg = @"邮件发送失败";
[self alertWithTitle:nil msg:msg];
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)alertWithTitle:(NSString *)title msg:(NSString *)message
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
}
- (void)showMailPicker
{
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil) {
if ([mailClass canSendMail]) {
[self displayMailComposerSheet];
}else{
[self launchMailAppOnDevice];
}
}else{
[self launchMailAppOnDevice];
}
}
- (void)displayMailComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[self presentModalViewController:picker animated:YES];
[picker release];
}
-(void)launchMailAppOnDevice
{
NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=my email!";
//@"mailto:support@shichangit.com?subject=意见与反馈"
NSString *body = @"&body=";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error
{
NSString *msg;
switch (result)
{
case MFMailComposeResultCancelled:
msg = @"邮件发送取消";
break;
case MFMailComposeResultSaved:
msg = @"邮件保存成功";
[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultSent:
msg = @"邮件发送成功";
[self alertWithTitle:nil msg:msg];
break;
case MFMailComposeResultFailed:
msg = @"邮件发送失败";
[self alertWithTitle:nil msg:msg];
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
- (void)alertWithTitle:(NSString *)title msg:(NSString *)message
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title
message:message
delegate:nil
cancelButtonTitle:@"确定"
otherButtonTitles:nil];
[alert show];
[alert release];
}
0 0
- iOS 之发送邮件的常用方法
- IOS邮件发送的方法
- ios发送邮件的2种方法
- 发送邮件的方法
- 发送邮件的方法
- 发送邮件的方法
- iOS 发送短信 和 发送邮件方法
- iOS开发之发送邮件
- iOS开发之发送邮件
- iOS开发之邮件发送
- 在Asp.Net中发送邮件的常用方法:
- iOS 关于邮件发送的三种方法
- 绑定发送邮件的方法
- C# 发送邮件的方法
- java发送邮件的方法
- linux发送邮件的方法
- android发送邮件的方法
- 解决ios设备自带邮箱只能接收邮件不能发送邮件问题的方法
- ping 192.168.1.1-t命令有什么用?
- ping命令的处理过程
- java学习之dom4j 对 xml的读取
- Memcached分析特点
- [转载]关于LWIP协议栈连续多次tcp_write后失败的解决过程
- iOS 之发送邮件的常用方法
- CSS2中display:table属性的用法详解
- (1) Appache Flume 中文介绍
- 获取内存信息
- AndroidStudio自定义属性xmlns无法识别问题解决in Gradle projects,always use http://schemas.android.com/apk/res-auto
- 持之以恒,善始善终
- strcpy
- 人民日报:那些“没脸回家”的年轻人应得到关注
- STL中的set容器的一点总结