相册访问权限
#import <AssetsLibrary/AssetsLibrary.h>
ALAuthorizationStatus status = [ALAssetsLibrary authorizationStatus];
if (status == ALAuthorizationStatusRestricted || status == ALAuthorizationStatusDenied)
{
// 无权限
// do something...
}
ALAuthorizationStatus解释
typedef NS_ENUM(NSInteger, ALAuthorizationStatus) {
// 用户还没有关于这个应用程序做出了选择
ALAuthorizationStatusNotDetermined NS_ENUM_DEPRECATED_IOS(6_0, 9_0) = 0, // User has not yet made a choice with regards to this application
// 这个应用程序未被授权访问图片数据。用户不能更改该应用程序的状态,可能是由于活动的限制,如家长控制到位。
ALAuthorizationStatusRestricted NS_ENUM_DEPRECATED_IOS(6_0, 9_0), // 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.
// 用户已经明确否认了这个应用程序访问图片数据
ALAuthorizationStatusDenied NS_ENUM_DEPRECATED_IOS(6_0, 9_0), // User has explicitly denied this application access to photos data.
// 用户授权此应用程序访问图片数据
ALAuthorizationStatusAuthorized NS_ENUM_DEPRECATED_IOS(6_0, 9_0) // User has authorized this application to access photos data.
} NS_DEPRECATED_IOS(6_0, 9_0, "Use PHAuthorizationStatus in the Photos framework instead");
在注释中我们可以看到苹果提示我们在Photos framework
中可以使用PHAuthorizationStatus
进行权限状态的判断
关于PHAuthorizationStatus
在8.0系统以后,新加入了Photos.framework
框架,我们可以利用框架中的PHAuthorizationStatus
进行权限状态判断。
- 如何使用
#import <Photos/PHPhotoLibrary.h>
PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied)
{
// 无权限
// do something...
}
- 解释
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);
相机访问权限
#import <AVFoundation/AVCaptureDevice.h>
AVAuthorizationStatus status = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (status == AVAuthorizationStatusRestricted || status == AVAuthorizationStatusDenied)
{
// 无权限
// do something...
}
AVAuthorizationStatus解释
typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {
// 表明用户尚未选择关于客户端是否可以访问硬件
AVAuthorizationStatusNotDetermined = 0,
// 客户端未被授权访问硬件的媒体类型。用户不能改变客户机的状态,可能由于活跃的限制,如家长控制
AVAuthorizationStatusRestricted,
// 明确拒绝用户访问硬件支持的媒体类型的客户
AVAuthorizationStatusDenied,
// 客户端授权访问硬件支持的媒体类型
AVAuthorizationStatusAuthorized
} NS_AVAILABLE_IOS(7_0) __TVOS_PROHIBITED;
/*!
@enum AVAuthorizationStatus
@abstract
Constants indicating the client's authorization to the underlying hardware supporting a media type.
@constant AVAuthorizationStatusNotDetermined
Indicates that the user has not yet made a choice regarding whether the client can access the hardware.
@constant AVAuthorizationStatusRestricted
The client is not authorized to access the hardware for the media type. The user cannot change
the client's status, possibly due to active restrictions such as parental controls being in place.
@constant AVAuthorizationStatusDenied
The user explicitly denied access to the hardware supporting a media type for the client.
@constant AVAuthorizationStatusAuthorized
The client is authorized to access the hardware supporting a media type.
*/
关于相机、相册图像的读取
有关相机、相册中图像的读取参见:iOS从相册和照相机读取图片(UIImagePickerController)
版权声明:出自MajorLMJ技术博客的原创作品 ,转载时必须注明出处及相应链接!