Camera permissions and album permissions use block to determine

Source: Internet
Author: User

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

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.