The. h file
+ (void) Camaracanuse: (qtcamaracanuse) camaracanuse camaranotcanuse: (qtcamaranotcanuse) camaranotcanuse ShowAlert: ( BOOL) Showalert showmsg: (nsstring*) showmsg;
+ (void) Photocanuse: (qtphotocanuse) photocanuse photonotcanuse: (qtphotonotcanuse) photonotcanuse ShowAlert: (BOOL) Showalert showmsg: (nsstring*) showmsg;
In the. m file
Bottom to determine if camera permissions and photos are turned on
+ (void) Camaracanuse: (qtcamaracanuse) camaracanuse camaranotcanuse: (qtcamaranotcanuse) camaranotcanuse ShowAlert: ( BOOL) Showalert showmsg: (nsstring*) showmsg{
BOOL canuse = [self Camarahadauthorizationandshowalert:showalert showmsg:showmsg];
if (canuse) {
Camaracanuse (Canuse);
}else{
Camaranotcanuse (Canuse);
}
}
+ (void) Photocanuse: (qtphotocanuse) photocanuse photonotcanuse: (qtphotonotcanuse) photonotcanuse ShowAlert: (BOOL) Showalert showmsg: (nsstring*) showmsg {
BOOL canuse = [self Checkphotoauthorizationandshowalert:showalert showmsg:showmsg];
if (canuse) {
Photocanuse (Canuse);
}else{
Photonotcanuse (Canuse);
}
}
+ (BOOL) Camarahadauthorizationandshowalert: (bool) show ShowMsg: (nsstring*) showmsg{
NSString *mediatype = avmediatypevideo;//Or Avmediatypeaudio
Avauthorizationstatus authstatus = [Avcapturedevice authorizationstatusformediatype:mediatype];
NSLog (@ "---authorization status:--------%ld", (long) authstatus);
This status was normally not Visible-the Avcapturedevice class methods for discovering devices does not return devices the User is restricted from accessing.
if (Authstatus ==avauthorizationstatusrestricted) {
NSLog (@ "Restricted, Authorization Limit");
return NO;
}else if (authstatus = = avauthorizationstatusdenied) {
The user has explicitly denied permission for media capture.
NSLog (@ "Denied, Authorization Denied"); It's supposed to be this, if not allowed.
NSString *showstr = @ "Please allow access to the camera in the device's \ settings-privacy-camera \". ";
if (Strnotnil (showmsg)) {
Showstr = showmsg;
}
if (show) {
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "hint"
Message:showstr
Delegate:self
cancelbuttontitle:@ "OK"
Otherbuttontitles:nil];
[Alert show];
}
return NO;
}
else if (authstatus = = avauthorizationstatusauthorized) {//Allow access
The user has explicitly granted permission for media capture, or explicit user permission are not necessary for the Medi A type in question.
NSLog (@ "Authorized, authorized");
return YES;
}else if (authstatus = = avauthorizationstatusnotdetermined) {
EXPLICIT user permission is required for media capture, but the user have not yet granted or denied such permission.
[Avcapturedevice Requestaccessformediatype:mediatype completionhandler:^ (BOOL granted) {
if (granted) {//Click on Allow access when called
The media needs to capture the user's explicit permission, but the user has not granted or denied the license.
NSLog (@ "Granted access to%@", mediatype);
}
else {
NSLog (@ "Not granted access to%@", mediatype);
}
}];
return NO;
}else {
return YES;
NSLog (@ "Unknown authorization status!");
}
}
+ (BOOL) Checkphotoauthorizationandshowalert: (bool) show ShowMsg: (nsstring*) showmsg{
Alauthorizationstatus author = [Alassetslibrary authorizationstatus];
if (author = = Alauthorizationstatusrestricted | | author ==alauthorizationstatusdenied)
{
if (show) {
NSString *showstr = @ "Please allow access to the camera in the device's \ settings-privacy-photos \". ";
if (Strnotnil (showmsg)) {
Showstr = showmsg;
}
No permissions
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "hint"
Message:showstr
Delegate:self
cancelbuttontitle:@ "OK"
Otherbuttontitles:nil];
[Alert show];
}
Eclog (@ "album not Authorized");
return NO;
}else{
return YES;
Eclog (@ "album authorized");
}
}
Five places to use
Post (contains two)
Add case Details
Personal Center Add Avatar
Medical Examination Surface Diagnosis
Block one line of code, can use the callback block can not be used callback block set whether to need a box, whether you need to write the prompt text
Camera permissions and album permissions use block to determine