您的位置:首页 > 其它

发短信/邮件/打电话

2016-04-22 09:30 417 查看
1.发短信

1.1简单方式

不能指定发短信的内容

不能回到原来的应用

<span style="font-size:18px;">
- (IBAction)sendMsg:(id)sender {
NSURL *url = [NSURL URLWithString:@"sms://1860253****"];
[[UIApplication sharedApplication] openURL:url];
}
</span>

1.2

<span style="font-size:18px;">
#import <MessageUI/MessageUI.h>
- (void)sendMsgToPhones:(NSArray *)phones title:(NSString *)title body:(NSString *)body {
//判断设备是否支持发短信
if ([MFMessageComposeViewController canSendText]) {
//创建发短信的控制器
MFMessageComposeViewController *msgController = [MFMessageComposeViewController new];
//接收者
msgController.recipients = phones;
msgController.title = title;
msgController.body = body;
//代理
msgController.messageComposeDelegate = self;
msgController.navigationBar.tintColor = [UIColor redColor];
[self presentViewController:msgController animated:YES completion:nil];
} else {
NSLog(@"这个设备不支持发短信");
}

}

- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
[self dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case MessageComposeResultCancelled:
NSLog(@"取消");
break;

case MessageComposeResultSent:
NSLog(@"成功");
break;

case MessageComposeResultFailed:
NSLog(@"失败");
break;

default:
break;
}
}

- (IBAction)sendMsg:(id)sender {
[self sendMsgToPhones:@[@"186025*****"] title:@"新短信" body:@"测试发短信"];
}
</span>


2.发邮件
<span style="font-size:18px;">
- (IBAction)sendMail:(id)sender {
if ([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailController = [MFMailComposeViewController new];
[mailController setSubject:@"我的邮件"];
[mailController setToRecipients:@[@"862071994@qq.com"]];
//抄送
//mailController setCcRecipients:
//密送
//mailController setBccRecipients:
[mailController setMessageBody:@"这是我的周报<font color=\"blue\" size =15 > 周报的内容 </font> 请审阅" isHTML:YES];
//附件
UIImage *image = [UIImage imageNamed:@"u=1713462169,1947795988&fm=15&gp=0"];
NSData *data = UIImagePNGRepresentation(image);
[mailController addAttachmentData:data mimeType:@"image/png" fileName:@"abc.png"];
mailController.mailComposeDelegate = self;
[self presentViewController:mailController animated:YES completion:nil];
} else {
NSLog(@"这个设备不支持发邮件");
}
}

- (void)mailComposeController:(MFMailComposeViewController *)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError *)error {
[self dismissViewControllerAnimated:YES completion:nil];
switch (result) {
case MFMailComposeResultCancelled:
NSLog(@"取消");
break;

case MFMailComposeResultFailed:
NSLog(@"失败");
break;

case MFMailComposeResultSaved:
NSLog(@"保存");
break;

case MFMailComposeResultSent:
NSLog(@"成功");
break;

default:
break;
}
}
</span>


3.打电话

//直接呼叫
- (void)tela {
NSURL *url = [NSURL URLWithString:@"tel://18602534746"];
[[UIApplication sharedApplication] openURL:url];
}
//会有提示,取消或呼叫;上线可能被拒绝
- (void)telb {
NSURL *url = [NSURL URLWithString:@"telprompt://18602534746"];
[[UIApplication sharedApplication] openURL:url];
}
//有提示,不被拒绝
- (void)telc {
NSURL *url = [NSURL URLWithString:@"tel://18602534746"];
if (_webView == nil) {
_webView = [[UIWebView alloc]initWithFrame:CGRectZero];
}
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: