系统SDK介绍-02
系统SDK介绍
- 打开相册选择图片
- 打开相册选择视频
- 打开相机拍摄图片
- 打开相机拍摄视频
配置权限:
在info.plist文件中添加需要的权限
- 相机权限:Privacy - Camera Usage Description 允许此权限才能使用相机功,这样才能录制视频,并且想要保存图片。
- 相册权限:Privacy - Photo Library Usage Description 允许此权限才能使用系统相册。
- 麦克风权限:Privacy - Microphone Usage Description 获取麦克风权限不然会崩,只有允许此权限才能录音。
判断是否权限
#pragma mark - 权限判断
- (BOOL)authorizationCamera {NSString *mediaType = AVMediaTypeVideo;AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){return false;}return true;
}
复制代码
配置选项
typedef NS_ENUM(NSInteger, LZSystemPhotoSelectorType) {LZSystemPhotoSelectorTypeVideo, // 选择视频LZSystemPhotoSelectorTypePhoto, // 选择图片
};typedef NS_ENUM(NSInteger, LZSystemOpenDeviceType) {LZSystemOpenDeviceTypeCamera, // 打开相机LZSystemOpenDeviceTypeVideo, // 打开摄像机
};
复制代码
接口文件
#import <Foundation/Foundation.h>NS_ASSUME_NONNULL_BEGINtypedef NS_ENUM(NSInteger, LZSystemPhotoSelectorType) {LZSystemPhotoSelectorTypeVideo, // 选择视频LZSystemPhotoSelectorTypePhoto, // 选择图片
};typedef NS_ENUM(NSInteger, LZSystemOpenDeviceType) {LZSystemOpenDeviceTypeCamera, // 打开相机LZSystemOpenDeviceTypeVideo, // 打开摄像机
};@interface LZSystemPhotoSelector : NSObject+ (instancetype)selector;/**选择图片或视频@param type 类型@param allowsEditing 是否允许编辑@param resultFile 选择结果,图片是UIImage 视频是NSUrl*/
- (void)lz_openAblumWithType:(LZSystemPhotoSelectorType)type allowsEditing:(BOOL)allowsEditing resultFile:(void(^)(id info))resultFile;/**打开相机或摄像机@param type 类型@param allowsEditing 是否拍摄完成进行编辑@param resultFile 选择结果,图片是UIImage 视频是NSUrl*/
- (void)lz_openDeviceWithType:(LZSystemOpenDeviceType)type allowsEditing:(BOOL)allowsEditing resultFile:(void(^)(id info))resultFile;@endNS_ASSUME_NONNULL_END
复制代码
实现文件
#import "LZSystemPhotoSelector.h"
#import <UIKit/UIKit.h>
#import <AVFoundation/AVFoundation.h>
#import <AssetsLibrary/AssetsLibrary.h>
#import <MobileCoreServices/MobileCoreServices.h>#define kRootViewController UIApplication.sharedApplication.delegate.window.rootViewController@interface LZSystemPhotoSelector () <UIImagePickerControllerDelegate, UINavigationControllerDelegate>@property (nonatomic, copy) void (^resultFile)(id info);
@property (nonatomic, assign) BOOL allowsEditing;@end@implementation LZSystemPhotoSelector+ (instancetype)selector {static dispatch_once_t onceToken;static LZSystemPhotoSelector *selector;dispatch_once(&onceToken, ^{selector = [[LZSystemPhotoSelector alloc] init];});return selector;
}#pragma mark - 选择图片或视频
- (void)lz_openAblumWithType:(LZSystemPhotoSelectorType)type allowsEditing:(BOOL)allowsEditing resultFile:(void(^)(id info))resultFile {if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {resultFile(@"该设备暂时不支持");return;}self.allowsEditing = allowsEditing;self.resultFile = resultFile;UIImagePickerController *controller = [[UIImagePickerController alloc] init];controller.delegate = self;controller.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;if (type == LZSystemPhotoSelectorTypePhoto) {controller.mediaTypes = [NSArray arrayWithObjects:@"public.image", nil];} else {controller.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];}controller.allowsEditing = allowsEditing;[kRootViewController presentViewController:controller animated:true completion:nil];
}#pragma mark - 打开相机或摄像机
- (void)lz_openDeviceWithType:(LZSystemOpenDeviceType)type allowsEditing:(BOOL)allowsEditing resultFile:(void (^)(id _Nonnull))resultFile {if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {resultFile(@"该设备暂时不支持");return;}if (![self authorizationCamera]) {resultFile(@"暂无相机权限");return;}self.allowsEditing = allowsEditing;self.resultFile = resultFile;UIImagePickerController *controller = [[UIImagePickerController alloc] init];controller.delegate = self;controller.sourceType = UIImagePickerControllerSourceTypeCamera;if (type == LZSystemOpenDeviceTypeCamera) {controller.mediaTypes = [NSArray arrayWithObjects:@"public.image", nil];} else {controller.mediaTypes = [NSArray arrayWithObjects:@"public.movie", nil];}controller.allowsEditing = allowsEditing;[kRootViewController presentViewController:controller animated:true completion:nil];
}#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info {NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];if ([mediaType isEqualToString:(NSString *)kUTTypeImage]) {if (self.allowsEditing) {UIImage *editorImage = info[UIImagePickerControllerEditedImage];self.resultFile(editorImage);} else {UIImage *editorImage = info[UIImagePickerControllerOriginalImage];self.resultFile(editorImage);}} else {NSURL *url = info[UIImagePickerControllerMediaURL];self.resultFile(url);}[picker dismissViewControllerAnimated:true completion:nil];
}- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {[picker dismissViewControllerAnimated:true completion:nil];
}#pragma mark - 权限判断
- (BOOL)authorizationCamera {NSString *mediaType = AVMediaTypeVideo;AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];if(authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied){return false;}return true;
}
@end
复制代码
系统SDK介绍-02相关推荐
- IOT [02] -- 物联网系统框架介绍
IOT [02] -- 物联网系统框架介绍 物联网系统框架介绍 1. 物联网设备如何接入到网络? 网络通信方式 物联网设备接入网络后如何开展M2M,M2C通信? 1. 基础应用:监控 2.进阶应用: ...
- Mint系统使用介绍,Mint系统安装,在Mint系统上搭建GPU环境,在Mint系统上安装Pycharm、Anaconda等软件,在Mint系统上安装cuda和cudnn
欢迎大家关注笔者,你的关注是我持续更博的最大动力 原创文章,转载告知,盗版必究 Mint系统使用介绍,Mint系统安装,在Mint系统上搭建GPU环境,在Mint系统上安装Pycharm.Anacon ...
- yocto Extensible SDK介绍
yocto Extensible SDK介绍 使用yocto Extensible SDK 1.1 为什么使用yocto Extensible SDK及其包含了什么 1.2 安装 Extensible ...
- Android名片扫描识别系统SDK
Android名片扫描识别系统SDK 一.Android名片扫描识别系统应用背景 这些年,随着移动互联的发展,APP应用成爆发式的增长,在很多APP中都涉及到对名片信息的录入,如移动CRM.移动端OA ...
- 微信群控SCRM客服系统SDK定制开发教程
微信群控SCRM客服系统SDK定制开发教程!出自秋天不穿秋裤,天冷也要风度的程序猿之手,必属精品! 今天给大家介绍如何使用聚播群控sdk(微信二次开发SDK)快速开发一个群控客服系统!使用此SDK也可 ...
- ST17H66 低功耗蓝牙SOC开发(1)—— SDK介绍
目录 1.资料获取 2.开发环境 3.ST17H66开发SDK获取 4.SDK介绍 4.1 components 4.2 example 4.3 lib 4.4 misc 1.资料获取 伦茨17Hxx ...
- 叠幻AR SDK介绍
SDK介绍 叠幻AR SDK是北京叠幻三维科技有限公司拥有完全自主知识产权的增强现实AR核心算法软件套件.叠幻AR SDK在浏览器端(Web)和小程序端通过极致优化增强现实AR的核心算法,为企业客户提 ...
- windows7、windows 2008和windows 2008 R2 的系统封装介绍
windows7.windows 2008和windows 2008 R2 的系统封装介绍 第一步: windows7.windows2008和windows 2008R2 中的sysprep.exe ...
- BCOS系统合约介绍
BCOS系统合约介绍 设计概述 实现概述 系统代理合约 节点管理合约 机构证书合约 权限管理合约 全网配置合约 自定义扩展 示例1-自定义业务配置合约 示例2-自定义业务权限Filter合约 设计概述 ...
最新文章
- OpenStack Neutron浅析(一)
- 跨链Cosmos(4)Tendermint Core
- zigbee绑定 使用_遇见-果加智能锁F2——使用体验
- C#中Bitmap类实现对图像操作的一些方法(转)
- php点链接直接现在文件吗,PHP实现点击a标签的href做链接时,直接保存文件(任何类型),而...
- C++查找一个目录下所有特定扩展名的文件
- C程序设计 4顺序程序设计
- IE10、IE11 ASP.Net 网站无法写入Cookie 问题
- JasperReport| JasperReport中使用自定义字体(font)
- html如何删除表单中的行,用jQuery remove()方法删除表格行(table tr)的写法
- 凯撒加密的python语言程序_python语言编程实现凯撒密码、凯撒加解密算法、
- 短视频开发app,Android 强制应用全局横屏或竖屏
- 乒乓球十一分制比赛规则_乒乓球赛制 乒乓球十一分制比赛规则
- 【金三银四】一个问题就知道你会不会CSS了
- 基于JAVASEOUL设计师品牌代购商城计算机毕业设计源码+系统+lw文档+部署
- 最实用大数据可视化分析工具
- 申请美国计算机科学博士,美国计算机博士申请案例分析
- unicode 和 GB2312 编码对应表
- 【学习笔记】无监督行人重识别
- 计算机毕业设计springboot通用项目的项目管理系统
热门文章
- 漫画 | 上班第一天,前端把后端告上县衙,还列了 5 宗罪!
- 炫酷,SpringBoot+Echarts实现用户访问地图可视化(附源码)
- Java中的锁原理、锁优化、CAS、AQS详解
- System.currentTimeMillis()竟然存在性能问题,这我能信?
- Spring Cloud第二篇:服务消费者RestTemplate+Ribbon
- Datawhale来浙大啦!
- 爱可可推荐!关于竞赛思路,方法和代码实践,Datawhale数据竞赛Baseline开源分享!...
- Meta元宇宙OS要黄?300人研发团队解散,关闭VR/AR操作系统研发
- 知乎热议:国家何时整治程序员的高薪现象?网友:用命和头发换的钱都被人眼红!...
- 《动手学深度学习》中文第二版预览版发布