美文网首页ios开发
iOS 权限判断(相机,相册,定位,录音)

iOS 权限判断(相机,相册,定位,录音)

作者: Justin_W | 来源:发表于2019-06-27 18:48 被阅读0次
    相机权限
    NSString *mediaType = AVMediaTypeVideo;
    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:mediaType];
    if(authStatus == ALAuthorizationStatusRestricted || authStatus == ALAuthorizationStatusDenied){
     //无权限
     NSString *tips = [NSString stringWithFormat:@"请在iPhone的”设置-隐私-相机“选项中,允许%@访问你的手机相机",NSLocalizedString(@"AppName",@"GMChatDemo")];
     [UIAlertView showWithTitle:@" " message:tips cancelButtonTitle:@"好" otherButtonTitles:nil tapBlock:nil];
     return;
     }
    
    
    相册权限
     ALAuthorizationStatus author = [ALAssetsLibrary authorizationStatus];
     if (author == kCLAuthorizationStatusRestricted || author ==kCLAuthorizationStatusDenied){
     //无权限
      NSString *tips = [NSString stringWithFormat:@"请在iPhone的”设置-隐私-照片“选项中,允许%@访问你的照片",NSLocalizedString(@"AppName",@"GMChatDemo")];
       [UIAlertView showWithTitle:@" " message:tips cancelButtonTitle:@"好" otherButtonTitles:nil tapBlock:nil];
                    return;
     }
    
    
    麦克风权限(录音等)
    + (BOOL)canRecord
    {
        __block BOOL bCanRecord = YES;
        if ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)
        {
            AVAudioSession *audioSession = [AVAudioSession sharedInstance];
            if ([audioSession respondsToSelector:@selector(requestRecordPermission:)]) {
                [audioSession performSelector:@selector(requestRecordPermission:) withObject:^(BOOL granted) {
                    bCanRecord = granted;
                }];
            }
        }
        return bCanRecord;
    }
    
    定位权限
    CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
     if (kCLAuthorizationStatusDenied == status || kCLAuthorizationStatusRestricted == status) {
      [self showHint:NSLocalizedString(@"location.open","please open location")];
      return;
        }
    
    

    相关文章

      网友评论

        本文标题:iOS 权限判断(相机,相册,定位,录音)

        本文链接:https://www.haomeiwen.com/subject/qehdcctx.html