iOS检测相机或者相册可用

来源:互联网 发布:数据库开发工程师要求 编辑:程序博客网 时间:2024/05/21 17:28

#define OSVersionIsAtLeastiOS7   ([[UIDevice currentDevice].systemVersion floatValue]>=7.0 ? YES:NO)  //定义的宏    

//检查相机是否可用

    if (OSVersionIsAtLeastiOS7) {

        NSString *mediaType =AVMediaTypeVideo;

        AVAuthorizationStatus authStatus = [AVCaptureDeviceauthorizationStatusForMediaType:mediaType];

        if (authStatus ==AVAuthorizationStatusDenied) {

            

            UIAlertView *alertView =[[UIAlertViewalloc]initWithTitle:nilmessage:@"请前往系统设置->隐私->相机,开启爱维宝贝权限"delegate:nilcancelButtonTitle:nilotherButtonTitles:@"确定",nil];

            [alertView show];

            return;

        }

    }

---------------------------------

    //检查相册是否可用

    if (OSVersionIsAtLeastiOS7) {

        ALAuthorizationStatus authStatus = [ALAssetsLibraryauthorizationStatus];

        if (authStatus ==ALAuthorizationStatusDenied) {       

            UIAlertView *alertView =[[UIAlertViewalloc]initWithTitle:nilmessage:@"请前往系统设置->隐私->相片,开启爱维宝贝权限"delegate:nilcancelButtonTitle:nilotherButtonTitles:@"确定",nil];

            [alertView show];

            return;

        }

        

    }


0 0
原创粉丝点击