直接上代码
1
2
3
4
5
6
7
8
9
|
#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 |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
|
#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 |
以上这篇iOS 请求权限封装类的实例代码就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。
原文链接:http://blog.csdn.net/z979451341/article/details/78757843