美文网首页
关于相机相册的一些实用技术

关于相机相册的一些实用技术

作者: IWorld看看外面的精彩 | 来源:发表于2017-01-21 17:39 被阅读9次

最近做项目遇到了一些问题,就搜集了一些资料,集中在了一起
感谢:
CSDN 博主 [小手一背爱谁谁]
http://blog.csdn.net/saw471/article/details/52679746
wentian的博客
http://www.2cto.com/kf/201608/532614.html
本人只是搬运工,如有冒犯,请见谅!

一、权限状态说明

相册、相机、通讯录等授权状态目前都有种,都可以对应以下几种状态:

AuthorizationStatusNotDetermined      // 用户从未进行过授权等处理,首次访问相应内容会提示用户进行授权
AuthorizationStatusAuthorized = 0,    // 用户已授权,允许访问
AuthorizationStatusDenied,            // 用户拒绝访问
AuthorizationStatusRestricted,        // 应用没有相关权限,且当前用户无法改变这个权限,比如:家长控制

二、权限获取(以下都是iOS8之后的)
1.相册权限
是否支持

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]

获取权限状态

PHAuthorizationStatus authStatus = [PHPhotoLibrary authorizationStatus];

请求权限

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
                }];

权限状态

typedef NS_ENUM(NSInteger, PHAuthorizationStatus) {
    PHAuthorizationStatusNotDetermined = 0, // User has not yet made a choice with regards to this application
    PHAuthorizationStatusRestricted,        // This application is not authorized to access photo data.
                                            // The user cannot change this application’s status, possibly due to active restrictions
                                            //   such as parental controls being in place.
    PHAuthorizationStatusDenied,            // User has explicitly denied this application access to photos data.
    PHAuthorizationStatusAuthorized         // User has authorized this application to access photos data.
} NS_AVAILABLE_IOS(8_0);

2.拍照权限
是否支持

[UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]

获取权限状态

AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];

请求权限

[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
                }];

权限状态

typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
    AVAuthorizationStatusNotDetermined = 0,
    AVAuthorizationStatusRestricted,
    AVAuthorizationStatusDenied,
    AVAuthorizationStatusAuthorized
} NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;

三、拒绝授权的处理
用户拒绝授权后,如果访问相应内容可能会出现一些类似没有数据的情况,此时应该给用户提示,引导用户授权。

跳转到应用设置:

NSURL *settingUrl = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:settingUrl]) {
    [[UIApplication sharedApplication] openURL:settingUrl];
}

四、info.plist 里面的相关配置

<!-- 相册 -->   
<key>NSPhotoLibraryUsageDescription</key>   
<string>App需要您的同意,才能访问相册</string>   

<!-- 相机 -->   
<key>NSCameraUsageDescription</key>   
<string>App需要您的同意,才能访问相机</string>   

<!-- 麦克风 -->   
<key>NSMicrophoneUsageDescription</key>   
<string>App需要您的同意,才能访问麦克风</string>   

<!-- 位置 -->   
<key>NSLocationUsageDescription</key>   
<string>App需要您的同意,才能访问位置</string>   

<!-- 在使用期间访问位置 -->   
<key>NSLocationWhenInUseUsageDescription</key>   
<string>App需要您的同意,才能在使用期间访问位置</string>   

<!-- 始终访问位置 -->   
<key>NSLocationAlwaysUsageDescription</key>   
<string>App需要您的同意,才能始终访问位置</string>   

<!-- 日历 -->   
<key>NSCalendarsUsageDescription</key>   
<string>App需要您的同意,才能访问日历</string>   

<!-- 提醒事项 -->   
<key>NSRemindersUsageDescription</key>   
<string>App需要您的同意,才能访问提醒事项</string>   

<!-- 运动与健身 -->   
<key>NSMotionUsageDescription</key> <string>App需要您的同意,才能访问运动与健身</string>   

<!-- 健康更新 -->   
<key>NSHealthUpdateUsageDescription</key>   
<string>App需要您的同意,才能访问健康更新 </string>   

<!-- 健康分享 -->   
<key>NSHealthShareUsageDescription</key>   
<string>App需要您的同意,才能访问健康分享</string>   

<!-- 蓝牙 -->   
<key>NSBluetoothPeripheralUsageDescription</key>   
<string>App需要您的同意,才能访问蓝牙</string>   

<!-- 媒体资料库 -->   
<key>NSAppleMusicUsageDescription</key>  <string>App需要您的同意,才能访问媒体资料库</string>  

*有个封装的工具类,可使用WTAuthorizationTool,里面还有通讯录的权限

pod "WTAuthorizationTool"

相关文章

  • 关于相机相册的一些实用技术

    最近做项目遇到了一些问题,就搜集了一些资料,集中在了一起感谢:CSDN 博主 [小手一背爱谁谁]http://bl...

  • 完美解决Android7.0调用系统相机拍照、访问相册 剪切的一

    关于Android7.0调用系统相机拍照、访问相册的一些问题:在Android6.0中Google提出了动态申请权...

  • 相册、相机

    添加依赖 1、清单文件里的权限 2、相机权限、相册权限 3、相机 4、相册 5、相机、相册返回的数据 6、上传 7...

  • H5 调用相机方法

    直接调用相机(测试安卓可以,iphone还是有相册) 调用相机 图片或者相册 调用相册

  • iOS开发相册,照相机的调用

    相册、相机UIImagePickerController 相册、相机的调用都是用此类,sourceType不一致协...

  • 相机相册

    1、创建继承于UIView的视图 2、在.m中进行布局与相机方法 3.在ViewControl中导入头文件,调用方法

  • 相机 相册

    从拍照,相册中获取图片 直接上代码吧 示例代码 申请权限AndroidManifest.xml activity_...

  • iOS关于相机相册权限设置

    iOS10之后,有一些童鞋提审应用时会出现因为没有对相机相册等权限的设置提醒而被拒绝,以及出现调取本地相册相机等出...

  • iOS关于相机相册权限设置

    iOS10出来之后,有一些童鞋提审应用时会出现因为没有对相机相册等权限的设置提醒而被拒绝,以及出现调取本地相册相机...

  • 相册 - 保存图片到相册

    实现点:保存相册到【相机胶卷】,同时保存到app自己创建的相册中(app自己的相册若没有创建,则创建) -【相机胶...

网友评论

      本文标题:关于相机相册的一些实用技术

      本文链接:https://www.haomeiwen.com/subject/jycnbttx.html