iOS 拍照与相片选择,在模拟器上拍照时做一个友好提示
- (IBAction)singleTapAction:(id)sender
{
UIActionSheet *sheet = [[UIActionSheet alloc]init];
[sheet addButtonWithTitle:@"拍照"];
[sheet addButtonWithTitle:@"从相册选择"];
[sheet addButtonWithTitle:@"取消"];
[sheet setCancelButtonIndex:2];
[sheet setDelegate:self];
sheet.tag = 255;
[sheet showInView:self.view];
}
#pragma mark - actionsheet delegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet.tag == 101) {
UIImagePickerController *pickController = [[UIImagePickerController alloc] init];
pickController.delegate = self;
[pickController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
if (buttonIndex == 0) {
AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if ((authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) && iOS7Later) {
// 无相机权限 做一个友好的提示
UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"无法使用相机" message:@"请在iPhone的""设置-隐私-相机""中允许访问相机" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"设置", nil];
[alert show];
} else { // 调用相机
// UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
pickController.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:pickController animated:YES completion:nil];
} else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"模拟器里不支持拍照,请在真机上测试!" delegate:nil cancelButtonTitle:nil otherButtonTitles:nil];
[NSTimer scheduledTimerWithTimeInterval:3.0f target:self selector:@selector(timerFireMethod:) userInfo:alert repeats:YES];
[alert show];
}
}
}
if (buttonIndex == 1) {
pickController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:pickController animated:YES completion:nil];
}
}
}
-(void)timerFireMethod:(NSTimer*)theTimer//弹出框
{
UIAlertView *promptAlert = (UIAlertView*)[theTimer userInfo];
[promptAlert dismissWithClickedButtonIndex:0 animated:NO];
promptAlert =NULL;
}
原文版权归作者所有,转载请注明来源
iOS 拍照与相片选择,在模拟器上拍照时做一个友好提示相关推荐
- FTP文件上传时的一个错误
最近做FTP上传的时候一直提示: AlexPilotti.FTPS.Common.FTPCommandException: Cannot STOR. 在 AlexPilotti.FTPS.Client ...
- MUI+HTML5+Plus 拍照或者相册选择图片并上传服务器
引入文件 css:mui.min.css.app.css.iconfont.css.feedback-page.css.font-awesome.min.css js:jquery.js.common ...
- 在模拟器上安装时一直停在instaling apk
问题: Installation failed with message null. It is possible that this issue is resolved by uninstallin ...
- 摄像头拍照功能是怎样实现的?自己动手做一个!
调用摄像头 需求分析 前期准备 设计流程 实现效果 重要代码 源码及程序整合 后续 需求分析 现如今,拍照已经融入我们的日常生活中了.我们在日常的工作生活中很多场景都会用到拍照功能.比如在登录网页或者 ...
- Android Stduio启动模拟器运行项目时做了什么
Android Studio每次打开模拟器运行项目,项目就会进行构建,那到底它构建的过程是什么样子的?深入的原理并不需要大家去了解,只需要知道它在run之后进行了哪些步骤,如下图所示.在buiId成功 ...
- python 天气预报地图_在树莓派上用 python 做一个炫酷的天气预报
#encoding: utf-8 importpygameimporttimeimportweatherAPIimportSystemInfofrom datetime importdatetime# ...
- Unity XCode iOS 实现拍照和相册选择上传头像
显示弹窗 通过UIAlertController来创建一个弹窗 #if defined(__cplusplus) extern "C" { #endif//导出接口供unity使用 ...
- html5图片上传时IOS和Android均显示摄像头拍照和图片选择
最近在做信开发时,发现<input type="file" />在IOS中可以拍照或从照片图库选择,而Android系统则显示资源管理器,无拍照选项,网上查找资料 ...
- 前端html input =“file“ ios/安卓解决无法选择图库/拍照问题
前端html input ="file" ios/安卓解决无法选择图库/拍照问题 背景 解决办法 延申 背景 在使用input上传图片的时候,有时候会出现安卓能拍照和选择图库,而i ...
最新文章
- POJ-2524-Ubiquitous Religions
- Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work.
- JavaScript-回调函数
- HTML5画布如何设置线的样式?
- [html] 你有使用过html5的rt标签吗?它有什么应用场景?
- 与gps优缺点_长缨在手,敢缚苍龙,中国北斗三号圆满收官,相比美国GPS怎样?...
- 惠普台式计算机系列,惠普发布设计笔记本、设计台式电脑等Z系列产品
- Ruby Variable Scope 简单讲解
- 样条表示---插值和逼近样条
- 两数之和python哈希_LeetCode-python 1.两数之和
- Hyper-V实战:高可用性-配置Hyper-V群集
- 解决ajax回调函数无返回值得问题
- SqlServer支持多表关联的分页存储过程
- 新型超级生物计算机简介,自然形成的超级生物计算机
- Linux驱动——设备树
- 华腾java_北大青鸟华腾学校 一个java痴迷者的独白
- libhv网络库源码剖析
- Win10系统禁用驱动程序强制签名
- mysql数据库character_关于MySQL如何修改character
- Linux环境下 微信支付退款 读取证书路径问题