IOS学习之—— 常用小功能,打电话 发短信 发邮件
2016-03-30 19:59
573 查看
打电话■ 最简单最直接的方式:直接跳到拨号界面 NSURL *url = [NSURL URLWithString:@"tel://10010"]; [[UIApplication sharedApplication] openURL:url]; ■ 缺点 电话打完后,不会自动回到原应用,直接停留在通话记录界面
方法二 ■ 拨号之前会弹框询问用户是否拨号,拨完后能自动回到原应用 NSURL *url = [NSURL URLWithString:@"telprompt://10010"]; [[UIApplication sharedApplication] openURL:url]; ■ 缺点 因为是私有API,所以可能不会被审核通过 方法三 创建一个UIWebView来加载URL,拨完后能自动回到原应用 if (_webView == nil) { _webView = [[UIWebView alloc] initWithFrame:CGRectZero]; } [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://10010"]]]; 需要注意的是:这个webView千万不要添加到界面上来,不然会挡住其他界面 发短信 : 方法一 ■ 直接跳到发短信界面,但是不能指定短信内容,而且不能自动回到原应用 NSURL *url = [NSURL URLWithString:@"sms://10010"]; [[UIApplication sharedApplication] openURL:url];
// 显示控制器
[self presentViewController:vc animated:YES completion:nil];
方法二 ■ 代理方法,当短信界面关闭的时候调用,发完后会自动回到原应用
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result
{
// 关闭短信界面
[controller dismissViewControllerAnimated:YES completion:nil];
if (result == MessageComposeResultCancelled) { NSLog(@"取消发送"); } else if (result == MessageComposeResultSent) { NSLog(@"已经发出"); } else { NSLog(@"发送失败"); }
}
发邮件:
■ 用自带的邮件客户端,发完邮件后不会自动回到原应用
NSURL *url = [NSURL URLWithString:@”mailto://10010@qq.com”];
[[UIApplication sharedApplication] openURL:url];
邮件发送后的代理方法回调,发完后会自动回到原应用
- (void)mailComposeController:(MFMailComposeViewController )controller didFinishWithResult:(MFMailComposeResult)result error:(NSError )error
{
// 关闭邮件界面
[controller dismissViewControllerAnimated:YES completion:nil];
if (result == MFMailComposeResultCancelled) { NSLog(@"取消发送"); } else if (result == MFMailComposeResultSent) { NSLog(@"已经发出"); } else { NSLog(@"发送失败"); }
}
相关文章推荐
- IOS学习之——彩票应用开发
- IOS学习之—— 图层与核心动画
- iOS新特性
- IOS学习之——触摸事件处理
- IOS学习之——手势解锁
- ios开发--GCD使用介绍:4-延迟执行操作
- iOS之Nib和Xib以及storyboard(故事版)
- IOS学习之——画板 涂鸦
- iOS storyboard中设置TableView的headerview 和 footerview
- IOS学习之——背景平铺
- IOS学习之——位图上下文 -- 水印图片
- IOS学习之—— 定时器 NSTimer 和 CADisplayLink 类的使用
- IOS学习之——图形上下文
- IOS学习之——Modal( 登陆,注册)
- IOS-推送通知
- IOS学习之——静态单元格
- IOS学习之——通知中心NSNotificationCenter
- IOS学习之——延迟执行
- IOS学习之——自定义代理delegate
- IOS学习之—— xib的用法--自定义View