Tool method to determine non-permitted access to iOS cameras, albums

Source: Internet
Author: User


1. Import Class Library

#import <AssetsLibrary/AssetsLibrary.h>#import <AVFoundation/AVFoundation.h>


2, determine whether to allow the use of the camera

#pragmaMark-Confirm that the camera is allowed access//returns 1 (YES) to indicate that the camera is not available. Returns 0 (NO) indicates the camera is available+(BOOL) checkcameracanuse{BOOL flag=NO; //Capture capture, videoAvauthorizationstatus status =[Avcapturedevice Authorizationstatusformediatype:avmediatypevideo]; Switch(status) { CaseAvauthorizationstatusauthorized://Approved             Break;  CaseAvauthorizationstatusrestricted://Restricted Limit         CaseAvauthorizationstatusdenied://Reject         CaseAvauthorizationstatusnotdetermined://not sureFlag =YES;  Break; }        returnFlag;}


3, judge the non-permitted use of albums

typedef ns_enum (Nsinteger, alauthorizationstatus) {alauthorizationstatusnotdetermined=0,//the user has not made a choice about this applicationAlauthorizationstatusrestricted,//This application does not have permission to access photo data. //users cannot change the state of this application, possibly due to activity limitations, such as where parental control is. Alauthorizationstatusdenied,//The user has denied access to the photo data for this application. Alauthorizationstatusauthorized//the user has authorized the application to access the photo data. } __osx_available_starting (__MAC_NA,__IPHONE_6_0);#pragmaMark-Determine if the album is allowed to use//return 1 (YES) indicates that the album is available. Returns 0 (NO) indicates that the album is not available+(BOOL) checkalassetslibrarycanuse{BOOL flag=NO; Alauthorizationstatus author=[Alassetslibrary Authorizationstatus]; Switch(author) { CaseAlauthorizationstatusnotdetermined://the user has not made a choice about this application         CaseAlauthorizationstatusrestricted://This app cannot access photo data, such as parental restrictions         CaseAlauthorizationstatusdenied://user has denied this app access to album data             Break;  Casealauthorizationstatusauthorized:{//user has authorized the app to access photo dataFlag =YES;  Break; }        default:             Break; }        returnFlag;}

Tool method to determine non-permitted access to iOS cameras, albums

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.