zoukankan      html  css  js  c++  java
  • ios 查询相册/摄像头/麦克风 的使用权限


    www.MyException.Cn  网友分享于:2015-06-21  浏览:0次
     
     
    iOS如何判断应用是否开启摄像头权限

    AVAuthorizationStatus authStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];  

    typedef NS_ENUM(NSInteger, AVAuthorizationStatus) {

    AVAuthorizationStatusNotDetermined = 0, //点击允许访问时调用  //用户明确许可与否,媒体需要捕获,但用户尚未授予或拒绝许可。

    AVAuthorizationStatusRestricted, 

    AVAuthorizationStatusDenied,   //不允许

    AVAuthorizationStatusAuthorized   //允许访问 

    } NS_AVAILABLE_IOS(7_0);

     

    麦克风权限检测:

    1. //检测麦克风功能是否打开  
    2.   [[AVAudioSessionsharedInstance]requestRecordPermission:^(BOOL granted) {  
    3.       if (!granted)  
    4.       {  
    5.           [ViewUtilalertViewWithString:NSLocalizedString(@"麦克风功能未开启",nil)];  
    6.       }  
    7.       else  
    8.       {  
    9.             
    10.           [selfrecord:sender];  
    11.       }  
    12.   }];

    相册权限检测:需要

    #import <AssetsLibrary/AssetsLibrary.h> //导入此类和AssetsLibrary.framework框架

    1. int author = [ALAssetsLibrary authorizationStatus];  
    2.             NSLog(@"author type:%d",author);  
    3.             if(author == ALAuthorizationStatusRestricted || author == ALAuthorizationStatusDenied) {  
    4.                 // The user has explicitly denied permission for media capture.  
    5.                 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"无法使用相册"  
    6.                                                                 message:@"请在iPhone的"设置-隐私-照片"中允许访问照片。"  
    7.                                                                delegate:self  
    8.                                                       cancelButtonTitle:@"确定"  
    9.                                                       otherButtonTitles:nil];  
    10.                 [alert show];  
    11.                 [alert release];  
    12.                 return;
  • 相关阅读:
    SpringMVC案例3----spring3.0项目拦截器、ajax、文件上传应用
    TCP/IP、UDP、 Http、Socket的差别
    HttpClient 图讲解明
    数据库设计--数据的垂直拆分
    未经处理的异常在 System.Data.dll 中发生。其它信息:在应使用条件的上下文(在 &#39;***&#39; 附近)中指定了非布尔类型的表达式。
    VMware 下扩展linux硬盘空间
    cocos2d_android 第一个游戏
    解决安卓程序安装没图标的问题
    Qt编译错误GL/gl.h: No such file or directory
    【编程题目】二元树的深度
  • 原文地址:https://www.cnblogs.com/blogfantasy/p/5213276.html
Copyright © 2011-2022 走看看