Solution to the black screen when iOS development calls the camera (reason: no camera access)

Source: Internet
Author: User

Solution to the black screen when iOS development calls the camera (reason: no camera access)

In the development process calls the system camera, but the page appears black screen, the reason is that only part of the camera permission to judge not according to the version of the system,

if ([[[[Uidevice Currentdevice] systemversion] floatvalue] >= 7.0) {Avauthorizationstatus Authstatus =                [Avcapturedevice Authorizationstatusformediatype:avmediatypevideo]; if (authstatus = = Avauthorizationstatusdenied | | authstatus = = avauthorizationstatusrestricted) {UIAler Tcontroller *alert = [Uialertcontroller alertcontrollerwithtitle:@ "Turn on camera Permissions" Message:nil Preferredstyle:            Uialertcontrollerstylealert]; Uialertaction *okaction = [Uialertaction actionwithtitle:@ "Go to set" Style:uialertactionstyledefault handler:^ (                Uialertaction * _nonnull action) {nsurl * url = [Nsurl urlwithstring:uiapplicationopensettingsurlstring]; if ([[[UIApplication sharedapplication] canopenurl:url]) {[UIApplication Sharedapplicati                On] openurl:url];            }            }];         Uialertaction *canleaction = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel Handler:nil];   [Alert addaction:okaction];            [Alert addaction:canleaction];            [Self Presentviewcontroller:alert animated:yes completion:nil];                   Return        }}else{Alauthorizationstatus author = [Alassetslibrary authorizationstatus]; if (author = = Kclauthorizationstatusrestricted | | author = = kclauthorizationstatusdenied) {uialertcontr Oller *alert = [Uialertcontroller alertcontrollerwithtitle:@ "Turn on camera Permissions" Message:nil Preferredstyle:            Uialertcontrollerstylealert]; Uialertaction *okaction = [Uialertaction actionwithtitle:@ "Go to set" Style:uialertactionstyledefault handler:^ (                Uialertaction * _nonnull action) {nsurl * url = [Nsurl urlwithstring:uiapplicationopensettingsurlstring]; if ([[[UIApplication sharedapplication] canopenurl:url]) {[UIApplication Sharedapplicati                On] openurl:url];            }            }]; Uialertaction *canleaction = [Uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel Handler:nil];            [Alert addaction:okaction];            [Alert addaction:canleaction];            [Self Presentviewcontroller:alert animated:yes completion:nil];        Return }    }

Solution to the black screen when iOS development calls the camera (reason: no camera access)

Related Article

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.