iOS 实用功能汇总(2)
2017-04-13 16:52
162 查看
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]];
相关文章推荐
- iOS 实用功能汇总(1)
- iOS培训篇——BOOL强大的实用功能介绍
- IOS实用功能之截图(来自相册和拍照)
- iOS开发之--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook功能开发汇总
- iOS 生成图片验证码(实用功能)
- [整理成书]关于webAPP实用功能点的集成与编写汇总
- unity3d实用小功能脚本汇总
- IOS 仿淘宝购物列表一键TOP置顶,小功能,挺实用
- 【实用新功能】移动开发者需要知道的iOS 10新特性
- deadline实用功能汇总,财主的粮仓
- iOS 8 beta 5新功能汇总:照片优化存储
- iOS 开发中实现打电话功能实用代码
- ios 开发超实用技巧:Xcode里批量修改 || 工程名 || 变量名 || 修改类名 || 自动封装代码Refactor功能
- iOS开发:手机QQ拖拽消除未读消息特效("一键下班"功能)相关资源汇总
- iOS开发之--内购、GameCenter、iCloud、Passbook功能开发汇总
- IOS实用功能之截图(来自相册和拍照)
- iOS 8 的 51 个炫酷功能汇总
- iOS开发入口类各方法功能汇总
- iOS手机功能汇总