iOS 实用功能汇总(2)
来源:互联网 发布:linux 查看网卡流量 编辑:程序博客网 时间:2024/06/08 14:32
1.打电话
1.第一种方法
这种方法在iOS8上测试的是不会出现弹框,直接进入到拨打电话界面,结束通话后会回到App界面。先跳出程序再进入到到系统的打电话程。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel:%@",@"10010"]]];
2.第二种方法(慎用)
这种方法提交审核的时候,可能会被拒,所以慎用。。。最好不用。。。
这种方法会出现弹框,结束通话后会回到App界面。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"telprompt://%@",@"10010"]]];
3.第三种方法
这种方法也会有弹框,结束通话后回到App界面,这种较第一种的区别在于: 一直都在自己的app中运行,没有出去过。
NSMutableString *str=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"10010"]; UIWebView *callWebview = [[UIWebView alloc] init]; [callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str]]]; [[UIApplication sharedApplication].keyWindow addSubview:callWebview];
发短信
需要导入MessageUI框架,#import <MessageUI/MessageUI.h>
if (![MFMessageComposeViewController canSendText]) return;MFMessageComposeViewController *vc = [[MFMessageComposeViewController alloc] init]; // 设置短信内容(这里可以设置短信内容,也可以不设置) //vc.body = @"Hello!"; // 设置收件人列表(这里可以指定收件人,也可以不设置) //vc.recipients = @[@"10010", @"10086"]; // 设置代理 vc.messageComposeDelegate = self; // 显示控制器 [self presentViewController:vc animated:YES completion:nil];
还要实现代理方法MFMessageComposeViewControllerDelegate
:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result{ // 关闭短信界面 [controller dismissViewControllerAnimated:YES completion:nil]; if (result == MessageComposeResultCancelled) { NSLog(@"取消发送"); } else if (result == MessageComposeResultSent) { NSLog(@"已经发出"); } else { NSLog(@"发送失败"); }}
发邮件
和发短信一样,只不过是MFMailComposeViewController
/ 不能发邮件if (![MFMailComposeViewController canSendMail]) return;MFMailComposeViewController *vc = [[MFMailComposeViewController alloc] init];// 设置邮件主题[vc setSubject:@"Hello"];// 设置邮件内容[vc setMessageBody:@"How are you?" isHTML:NO];// 设置收件人列表[vc setToRecipients:@[@"66666@qq.com"]];// 设置抄送人列表[vc setCcRecipients:@[@"66666@qq.com"]];// 设置密送人列表[vc setBccRecipients:@[@"66666@qq.com"]];// 添加附件(一张图片)UIImage *image = [UIImage imageNamed:@"pic.jpeg"];NSData *data = UIImageJPEGRepresentation(image, 0.5);[vc addAttachmentData:data mimeType:@"image/jepg" fileName:@"pic.jpeg"];// 设置代理vc.mailComposeDelegate = self;// 显示控制器[self presentViewController:vc animated:YES completion:nil];
同样实现代理:
- (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(@"发送失败"); }}
跳转AppStore
NSString *str = [NSString stringWithFormat: @"itms-apps://itunes.apple.com/cn/app/id%@?mt=8", appid];[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
0 0
- iOS 实用功能汇总(2)
- iOS 实用功能汇总(1)
- VC实用功能(2)
- IOS实用功能之截图(来自相册和拍照)
- deadline实用功能汇总,财主的粮仓
- VC实用功能(1)
- iOS面试题汇总 (2)
- CATransform3D汇总(IOS)
- 从头认识java-14.4 Java提供的数组的实用功能(2)
- Vc++实用功能(性能分析,内存泄漏)
- evbuffer:缓冲IO实用功能 (十) (转)
- [整理成书]关于webAPP实用功能点的集成与编写汇总
- IOS汇总
- SQLServer 工具箱(脚本排序+清除日志+更多实用功能)
- 安卓常用实用功能代码片大全(长期更新)
- pycharm 使用心得(七)一些实用功能介绍
- Android实用功能(一)CollapsingToolbarLayout实现标题栏的伸缩
- HTML实用功能
- NYOJ349_Sorting It All Out
- ssm框架事务配置详解
- iOS 百度地图运动轨迹的角度
- 约瑟夫环的数学优化方法
- office2010 word 关闭很慢(转)
- iOS 实用功能汇总(2)
- java中引用类型的使用
- void类型与void类型指针
- Follow me 挑战程序与设计
- JSON和JSONP
- 十一注解方式配置Bean
- Vue自定义过滤器
- sed使用
- RHEL7--UNIT11--网络管理