您的位置:首页 > 移动开发 > IOS开发

iOS检测相机或者相册可用

2016-07-22 16:48 351 查看
#define OSVersionIsAtLeastiOS7   ([[UIDevice currentDevice].systemVersion floatValue]>=
7.0 ? YES:NO)  //定义的宏    
//检查相机是否可用
    if (OSVersionIsAtLeastiOS7) {
        NSString *mediaType =
AVMediaTypeVideo;
        AVAuthorizationStatus authStatus = [AVCaptureDevice
authorizationStatusForMediaType:mediaType];
        if (authStatus ==
AVAuthorizationStatusDenied) {
            
            UIAlertView *alertView =[[UIAlertView
alloc]initWithTitle:nil
message:@"请前往系统设置->隐私->相机,开启爱维宝贝权限"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"确定",
nil];
            [alertView show];
            return;
        }
    }
---------------------------------

    //检查相册是否可用
    if (OSVersionIsAtLeastiOS7) {
        ALAuthorizationStatus authStatus = [ALAssetsLibrary
authorizationStatus];
        if (authStatus ==
ALAuthorizationStatusDenied) {       
            UIAlertView *alertView =[[UIAlertView
alloc]initWithTitle:nil
message:@"请前往系统设置->隐私->相片,开启爱维宝贝权限"
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:@"确定",
nil];
            [alertView show];
            return;
        }
        
    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: