iPhone系统权限

  • 需要引用到的头文件有
#import 
#import 
#import 
#import 
#import 
  • 相册权限
+ (BOOL) isPhotosAuthorized;
{
    ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
    if (author == ALAuthorizationStatusDenied)
    {
        return NO;
    }
    return YES;
}
  • 照相机权限
+ (BOOL) isCameraAuthorized
{
    AVAuthorizationStatus avStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
    BOOL isHaveCamera = (avStatus == AVAuthorizationStatusAuthorized || avStatus == AVAuthorizationStatusNotDetermined);
    if (!isHaveCamera)
    {
        return NO;
    }
    return YES;
}
  • 麦克风权限
+ (BOOL) isMicroPhoneAuthorized
{
        __block BOOL bCanRecord = YES;
        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        if ([audioSession respondsToSelector:@selector(requestRecordPermission:)])
        {
            [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
            bCanRecord = granted;
            }];
        }
        return bCanRecord;
}
  • 通知权限
+ (BOOL) isNotificationAuthorized
{
        BOOL isAllowNotifi = NO;
        UIUserNotificationSettings *setting = [[UIApplication sharedApplication] currentUserNotificationSettings];
        if (UIUserNotificationTypeNone != setting.types)
        {
            isAllowNotifi = YES;
        }
        return isAllowNotifi;
}
  • 定位权限
+ (BOOL)isLocatonAuthorized
{
        if (![CLLocationManager locationServicesEnabled])
        {
            return NO;
        }
    
        CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
        if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorizedAlways )
        {
            return YES;
        }
        return NO;
}
  • 通讯录权限
+ (BOOL) isContactsAuthorized
{
        if (ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusDenied || ABAddressBookGetAuthorizationStatus() == kABAuthorizationStatusRestricted)
        {
            return NO;
        }
        return YES;
}

你可能感兴趣的:(iPhone系统权限)