#import <AVFoundation/AVFoundation.h>

#import <AVFoundation/AVCaptureDevice.h>

<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

// 以sheet样式供用户选择

UIActionSheet *sheet;

if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

sheet = [[UIActionSheet alloc] initWithTitle:nil delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从相册中选取", nil];

} else { // 模拟器无相机

sheet = [[UIActionSheet alloc] initWithTitle:nildelegate:self cancelButtonTitle:@"取消"destructiveButtonTitle:nil otherButtonTitles:@"从相册中选取", nil];

}

[sheet showInView:self.view];

#pragma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

UIImagePickerControllerSourceType sourceType;

// 判断是否支持相机

if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

switch (buttonIndex) {

case 0: {

// 相机  用户选择了相机

NSString *mediaType = AVMediaTypeVideo;

AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:mediaType];

if(authStatus != AVAuthorizationStatusAuthorized) { // 没有访问权限

UIAlertView *av = [[UIAlertViewalloc] initWithTitle:@"访问相机受限!" message:@""delegate:nil cancelButtonTitle:@"确认"otherButtonTitles:nil, nil];

[av show];

return;

}

sourceType = UIImagePickerControllerSourceTypeCamera;

break;

}

case 1: {

// 相册  用户选择了相册

NSString *mediaType = AVMediaTypeVideo;

AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:mediaType];

if(authStatus != AVAuthorizationStatusAuthorized) { // 没有访问权限

UIAlertView *av = [[UIAlertViewalloc] initWithTitle:@"访问相册受限!" message:@""delegate:nil cancelButtonTitle:@"确认"otherButtonTitles:nil, nil];

[av show];

return;

}

sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

break;

}

case 2: {

// 取消

return;

}

}

} else {

if (buttonIndex == 0) {

// 相册  用户选择了相册

NSString *mediaType = AVMediaTypeVideo;

AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:mediaType];

if(authStatus != AVAuthorizationStatusAuthorized) { // 没有访问权限

UIAlertView *av = [[UIAlertViewalloc] initWithTitle:@"访问相册受限!" message:@""delegate:nil cancelButtonTitle:@"确认"otherButtonTitles:nil, nil];

[av show];

return;

}

sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

} else {

return;

}

}

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

imagePickerController.sourceType = sourceType;

imagePickerController.allowsEditing = YES;

imagePickerController.delegate = self;

[selfpresentViewController:imagePickerController animated:YES completion:^{}];

}

#pragma mark - UIImagePickerControllerDelegate UINavigationControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

{

[picker dismissViewControllerAnimated:YEScompletion:^{}];

// 获取到的图片

UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];

_headIV.image = image;

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

[self dismissViewControllerAnimated:YEScompletion:^{}];

}

转载于:https://www.cnblogs.com/macrohong/p/4946605.html

iOS 获取系统相机相册相关推荐

  1. iOS 获取系统相册

    在iOS开发中经常会用到相册的图片,但是原生的UIImagePikerViewDelegate只能选取一张照片进行处理,这样管理起来比较麻烦,所以本次带来获取系统所有相册. 首先建一个继承NSObje ...

  2. iOS 基于PhotoKit 获取系统所有相册 以及所有照片 包括iCloud的处理 细节详解及实战代码

    前言 最近在做一个相册的项目,一开始觉得项目没什么难度,可是真正上手做了之后,发现难度不小,苹果新推出Photokit之后,获取相册中图片对象是快的,可是在获取到具体图片个人实战比较慢,同时还有icl ...

  3. android在主程序中调用图片,009android初级篇之APP中使用系统相机相册等集成应用...

    009android初级篇之APP中使用系统相机相册等集成应用 android应用中使用相机功能,大致有两种方式实现: 直接调用系统内部的相机程序,显示的也是系统预设的界面(简单,只有简单的拍照功能) ...

  4. Android开发 调用系统相机相册图片功能,解决小米手机拍照或者图片横竖相反问题,及小米手机相册图片路径问题

    Android开发 调用系统相机相册图片功能,解决小米手机拍照或者图片横竖相反问题,及小米手机相册图片路径问题 1.调用相机,兼容7.0 AndroidManifest配置 <providera ...

  5. IOS 获取摄像头/麦克风/相册 权限

    IOS 获取摄像头/麦克风/相册 权限 1.获取摄像头/麦克风权限 1.1.检测当前的权限状态 1.2.请求麦克风权限 2.获取相册权限 2.1.检测权限 2.2.请求授权 3.版本兼容 4.后台处理 ...

  6. IOS获取系统通讯录联系人信息

    2019独角兽企业重金招聘Python工程师标准>>> IOS获取系统通讯录联系人信息 一.权限注册 随着apple对用户隐私的越来越重视,IOS系统的权限设置也更加严格,在获取系统 ...

  7. iOS/swift之获取系统所有相册和照片录像、封装相册多选

    参考:http://www.hangge.com/blog/cache/detail_1512.html ios14 使用PHPicker获取相册(需要 import PhotosUI) 支持多选 支 ...

  8. 利用系统相机相册获取单张图片,兼容7.0

    场景 很多应用都有设置下头像之类的需求,都需要相机相册,但是在6.0的时候加上了运行时权限检测,7.0的时候限制了在应用建共享文件,就是之前相机相册使用的file://URI 不能使用了. 因为在7. ...

  9. iOS 获取系统时间(服务器时间)问题

    iOS 开发中我们经常用到获取系统时间,正常来说,我们只需要调用系统API即可 let currentDate = Date() let formatter = DateFormatter() // ...

  10. ios 调用系统相机为英文时的更改

    使用UIImagePickerViewController调用系统相机,当系统相机按钮为英文时. 在 info.plist 中添加 Localization native development re ...

最新文章

  1. Android之从Camera捕获图像讲解
  2. 哲学家就餐问题php代码,Python实现哲学家就餐问题实例代码
  3. [Leetcode][第889题][JAVA][根据前序和后序遍历构造二叉树][分治][递归]
  4. B端产品经理要掌握的基本功
  5. 博文视点大讲堂第6、7期开课
  6. mySQL中replace的用法
  7. android 热更新jar,Android热更新之so库的热更新
  8. soapui oracle groovy,SoapUI Groovy 使用实例
  9. Tesla特斯拉电动汽车电力驱动系统3D模型(含悬挂) Catia 附STEP
  10. Python的raw string原始字串转化为string一般字符串,还有结尾插入‘\‘的方法,还有把string转化为raw string
  11. esxi虚拟服务器网络搭建,小姜学网络(使用VMware ESXi 5.5搭建VMware虚拟化平台一)...
  12. Windows 9x、2K、XP、2003注册表大全
  13. python爬虫爬取今日头条_python 简单爬取今日头条热点新闻(一)
  14. ubuntu搜狗输入法
  15. 什么是交换机?什么是路由器?网络通信的底层原理到底是怎么回事?不清楚的程序猿快来科普下吧!
  16. [转]热电偶与热电阻的区别[2]
  17. 10款优秀的WordPress企业主题推荐
  18. 百度文库复制不了文字!!!
  19. linux系统用中文怎么说,Linux系统的Linux中文怎么读?
  20. 安装计算机软件教学设计,四年级信息技术《应用软件的安装》教学设计

热门文章

  1. 【Java程序设计】Java基础类库简介
  2. src refspec main does not match any
  3. flume流程之taildir-memory-hdfs
  4. Synopsys MetaWare for Linux 安装与编译指南
  5. 新潮传媒“小趋势”背后的巨变之力
  6. sybase修改默认字符集为cp936
  7. 【转】Data truncation: Truncated incorrect DOUBLE value:Mysql Update时
  8. OpenCV Mat 类型定义和赋值
  9. 人生的第一个js插件
  10. 未知宽高div水平垂直居中的3种方法