
在iOS应用中即使调用平台相册或手机,需要客户具备相应的权限,才可进行必定的操作。那在应用中怎样获得当前相册及手机的权限呢强制进入相机 相册 ios强制进入相机 相册 ios,有如下两种方法:其实两种形式基本一样,只是Apple 更改了API调用方式。
1、iOS 8.0以上系统

首先,导入应该的头文件以及AssetsLibrary框架。
#import <AssetsLibrary/AssetsLibrary.h>
然后即可获取权限
ALAuthorizationStatus author = [ALAssetsLibraryauthorizationStatus];
if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
//无权限
}if … 其他情况依次判断
所有权限状态如下:
typedef enum {
kCLAuthorizationStatusNotDetermined = 0, // 用户尚未做出选择这个应用程序的问候
kCLAuthorizationStatusRestricted, // 此应用程序没有被授权访问的照片数据。可能是家长控制权限
kCLAuthorizationStatusDenied, // 用户已经明确否认了这一照片数据的应用程序访问
kCLAuthorizationStatusAuthorized // 用户已经授权应用访问照片数据
}
2、iOS 8.0以上系统

首先,导入应该的头文件以及Photos框架。
#import <Photos/Photos.h>
然后即可获取权限
PHAuthorizationStatus authorStatus = [PHPhotoLibrary authorizationStatus];
NSLog(@"openGallery_authorStatus == %ld",(long)authorStatus);
if (authorStatus == PHAuthorizationStatusAuthorized){
//获取权限
}if … 其他情况依次判断
所有权限状态如下,跟上面一样,只是接口名称不同。
typedefNS_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);
3、iOS10以上系统

首先,需在项目对应的plist文件内添加“Privacy - Photo Library Usage Description”这个key,同时修改其值为“App needs your permission to access the Photo”类似这种的表明。
//获取相册访问权限
PHAuthorizationStatus photoStatus = [PHPhotoLibrary authorizationStatus];
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
dispatch_async(dispatch_get_main_queue(), ^{
switch (status) {
case PHAuthorizationStatusAuthorized: //已获取权限
break;
case PHAuthorizationStatusDenied: //用户已经明确否认了这一照片数据的应用程序访问
break;
case PHAuthorizationStatusRestricted://此应用程序没有被授权访问的照片数据。可能是家长控制权限
break;
default://其他。。。
break;
}
});
}];
二、判断用户访问相机权限

iOS7之前都可以访问相机,iOS7之后访问相机有权限修改
对相机的访问权限获得与相册类似,直接上代码
首先,导入应该的头文件以及AVFoundation框架。
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-122318-1.html
那里的岛礁有许多在自然状况下是当涨潮时处于海面以下的