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