iOS---常用权限判断

2018-07-05  本文已影响0人  不可雕的板蓝根

权限判断引入头文件

#import <AVFoundation/AVFoundation.h>
#import <Photos/PHPhotoLibrary.h>
#import <CoreLocation/CoreLocation.h>
+ (BOOL )authStatusCamara{
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    if (authStatus == AVAuthorizationStatusRestricted || authStatus == AVAuthorizationStatusDenied) {
//        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
//        if ([[UIApplication sharedApplication]canOpenURL:url]) {
//            [[UIApplication sharedApplication]openURL:url];
//            return NO;
//        }
        
        NSString* message = [NSString stringWithFormat:@"相机权限受限,请前往设置->%@->相机,打开权限!", APPNAME];
        MessageShow(message);
        return NO;
    }
    return YES;
}
+ (BOOL )authStatusAssets{
    
    PHAuthorizationStatus status = [PHPhotoLibrary authorizationStatus];
    if (status == PHAuthorizationStatusRestricted || status == PHAuthorizationStatusDenied){
        
        NSString* message = [NSString stringWithFormat:@"照片权限受限,请前往设置->%@->照片,打开权限!", APPNAME];
        MessageShow(message);
        return NO;
    }
    return YES;
}
+ (BOOL )authStatusLocation{
    
    CLAuthorizationStatus author = [CLLocationManager authorizationStatus];
    if (author == kCLAuthorizationStatusDenied || author == kCLAuthorizationStatusRestricted){
        
        NSString* message = [NSString stringWithFormat:@"位置权限受限,请前往设置->%@->位置,打开权限!", APPNAME];
        MessageShow(message);
        return NO;
    }
    return YES;
}
上一篇下一篇

猜你喜欢

热点阅读