代码改变世界

摄像头监測是否“授权”

2017-06-17 20:10  tlnshuju  阅读(303)  评论(0编辑  收藏  举报

ios7苹果公司增加了摄像头隐私设置选项:

在app中监測手机摄像头是否授权给APP:

#define PHOTOGRAPH_ACCREDIT \

    if(VALID_VERSION(7.0)){\
        if(!([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo] == AVAuthorizationStatusAuthorized)){\
                UIAlertView * alt = [[UIAlertView alloc] initWithTitle:@"未获得授权使用摄像头" message:@"请在iOS\"设置中\"-\"隐私\"-\"相机\"中打开" delegate:self cancelButtonTitle:nil otherButtonTitles:@"知道了", nil];\
                [alt show];\
                return;\
        }\

    }


我写了一个宏,在调用摄像头的地方前面增加(PHOTOGRAPH_ACCREDIT;),若没有在系统“设置”-“隐私”开启摄像头就会有这种效果: