iOS常用小功能的实现
2015-01-20 21:29
281 查看
iOS应用开发中有许多非常实用的小功能, 这些小功能的实现也非常的简单, 本文将这些小功能汇总,用于备忘。
1. 打电话功能的实现
实现打电话功能的方式有多种,其中最好的方式如下:
2. 发短信功能的实现
实现发短信的功能也有多种,但是下面的方式最佳:
3. 发邮件功能的实现
发邮件的功能实现有多种方式,推荐使用下面的方式:
4. 应用评分功能
下面的代码用于实现应用评分功能:
5. 打开常用的文件
在iOS开发中,如果想打开一些常见文件,比如html/txt/pdf/ppt等,都可以选择使用UIWebView打开,只需要告诉UiwebView的URL即可,如果想打开一个远程的共享资源,比如http协议下的资源,也可以调用系统自带的Safari浏览器
6. 关联到其他应用
有时候,需要在当前应用A中打开其他应用B,需要经过下面两步:
1.)首先,B应用有自己的URL地址(在info.plist中配置)
配置好的B应用的URL地址为: mj://ios.itcast.cn
2.) 接着在A应用中使用UIApplication完成跳转
Demo下载地址: http://download.csdn.net/detail/luozhonglan/8381037
1. 打电话功能的实现
实现打电话功能的方式有多种,其中最好的方式如下:
//利用UIWebView打电话 if (_webView == nil) { //WebView不需要显示,只需要实现打电话功能 _webView = [[UIWebView alloc] initWithFrame:CGRectZero]; } [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel://10010"]]];
2. 发短信功能的实现
实现发短信的功能也有多种,但是下面的方式最佳:
//2.使用MessageUI框架封装的功能 MFMessageComposeViewController *messageVC = [[MFMessageComposeViewController alloc] init]; messageVC.body = @"你吃翔了没?"; messageVC.recipients = @[@"10010", @"10086"]; //设置代理 messageVC.messageComposeDelegate = self; [self presentViewController:messageVC animated:YES completion:nil]; #pragma mask MFMessageComposeViewControllerDelegate - (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result { //关闭短信界面 [controller dismissViewControllerAnimated:YES completion:nil]; if (result == MessageComposeResultCancelled) { NSLog(@"取消发送"); }else if(result == MessageComposeResultSent){ NSLog(@"发送成功"); }else{ NSLog(@"发送失败"); } }
3. 发邮件功能的实现
发邮件的功能实现有多种方式,推荐使用下面的方式:
// 使用MessageUI框架封装的功能 MFMailComposeViewController *mailVC = [[MFMailComposeViewController alloc] init]; //设置邮件主题 [mailVC setSubject:@"会议"]; //设置邮件内容 [mailVC setMessageBody:@"今天下午你去吃翔吧!" isHTML:NO]; //设置收件人列表 [mailVC setToRecipients:@[@"123456@qq.com"]]; //设置抄送人列表 [mailVC setCcRecipients:@[@"987654321@qq.com"]]; //设置密送人列表 [mailVC setBccRecipients:@[@"7654@qq.com"]]; //添加一张附图(一张图片) UIImage *image = [UIImage imageNamed:@"aaa.png"]; //压缩图片 NSData *data = UIImagePNGRepresentation(image); [mailVC addAttachmentData:data mimeType:@"image/png" fileName:@"aaa.png"]; //设置代理 mailVC.mailComposeDelegate = self; [self presentViewController:mailVC animated:YES completion:nil]; #pragma mask MFMailComposeViewControllerDelegate - (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(@"发送失败"); } }
4. 应用评分功能
下面的代码用于实现应用评分功能:
//拿到应用的ID NSString *appid = @"123456"; NSString *str = [NSString stringWithFormat:@"itms-apps://ituns.apple.com/app/id%@?mt=8", appid]; NSURL *url = [NSURL URLWithString:str]; [[UIApplication sharedApplication] openURL:url];
5. 打开常用的文件
在iOS开发中,如果想打开一些常见文件,比如html/txt/pdf/ppt等,都可以选择使用UIWebView打开,只需要告诉UiwebView的URL即可,如果想打开一个远程的共享资源,比如http协议下的资源,也可以调用系统自带的Safari浏览器
NSURL *url = [NSURL URLWithString:@"http://m.baidu.com"]; [[UIApplication sharedApplication] openURL:url];
6. 关联到其他应用
有时候,需要在当前应用A中打开其他应用B,需要经过下面两步:
1.)首先,B应用有自己的URL地址(在info.plist中配置)
配置好的B应用的URL地址为: mj://ios.itcast.cn
2.) 接着在A应用中使用UIApplication完成跳转
NSURL *url = [NSURL URLWithString:@"mj://ios.itcast.cn"]; [[UIApplication sharedApplication] openURL:url];
Demo下载地址: http://download.csdn.net/detail/luozhonglan/8381037
相关文章推荐
- iOS软件开发添加电话、短信、邮件常用功能实现
- 在Cisco设备上实现IOS DHCP Server的功能
- 自己写了一个上传类,实现了常用的功能
- C# ASP.NET 最常用的通用权限的3个方法例子展示(每个功能一行代码实现)
- ios实现条形码扫描功能
- VISUAL C++软件开发中几个常用功能的实现
- ios实现条形码扫描功能
- 使用.net FtpWebRequest 实现FTP常用功能
- C# ASP.NET 最常用的通用权限的3个方法例子展示(每个功能一行代码实现)
- Windows Phone7天初学(3):常用功能实现
- VC常用功能及实现方法
- 使用asp.net FtpWebRequest 实现FTP常用功能
- 使用.net FtpWebRequest 实现FTP常用功能
- 软件开发中几个常用功能的实现
- 使用.net FtpWebRequest 实现FTP常用功能
- 使用.net FtpWebRequest 实现FTP常用功能 上传 下载 获取文件列表 移动 切换目录 改名
- 使用asp.net FtpWebRequest 实现FTP常用功能
- 我在开发过程总结的一套实现常用功能的函数
- 利用IOS提供的tclsh脚本功能实现快速测试