时间:2021-01-12 13:19:51 | 栏目:iOS代码 | 点击:次
直接上代码
#import <Foundation/Foundation.h> #import <AVFoundation/AVFoundation.h> #import <AssetsLibrary/AssetsLibrary.h> #import <Photos/Photos.h> #import <CoreLocation/CoreLocation.h> @interface PermissionUtil : NSObject +(Boolean)JudgeCameraPermission; +(Boolean)JudgeLocationPermission; @end
#import "PermissionUtil.h" @implementation PermissionUtil +(BOOL)isCanUsePhotos { if ([[[UIDevice currentDevice] systemVersion] floatValue] < 8.0) { ALAuthorizationStatus author =[ALAssetsLibrary authorizationStatus]; if (author == kCLAuthorizationStatusRestricted || author == kCLAuthorizationStatusDenied) { //无权限 return NO; } } else { PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus]; if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied) { //无权限 return NO; } } return YES; } +(Boolean)JudgeCameraPermission{ AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]; if (authStatus == AVAuthorizationStatusRestricted || authStatus ==AVAuthorizationStatusDenied||![self isCanUsePhotos]) { return NO; } return YES; } +(Boolean)JudgeLocationPermission{ if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) { return YES; }else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) { return NO; } return NO; } @end