iOS Red Vest Project Bug Summary (2)

Source: Internet
Author: User

Background: iOS calls the camera and accesses the gallery

First, call the camera or gallery:

-(void) Imgviewclick

{

Alauthorizationstatus author = [Alassetslibrary authorizationstatus];

Avauthorizationstatus authstatus = [Avcapturedevice authorizationstatusformediatype:avmediatypevideo];

Uialertcontroller *alertvc=[uialertcontroller alertcontrollerwithtitle:nil message:nil preferredStyle: Uialertcontrollerstyleactionsheet];

Uialertaction *cameraaction =[uialertaction actionwithtitle:@ "Camera" Style:uialertactionstyledefault handler:^ ( Uialertaction * _nonnull action) {

Uiimagepickercontroller *picker=[[uiimagepickercontroller Alloc]init];

if (authstatus = = Alauthorizationstatusrestricted | | authstatus = = alauthorizationstatusdenied) {

[Self resulthud:@] Please open your camera permissions in the settings! "];

No permission to boot to turn on the camera

Nsurl *url = [Nsurl urlwithstring:uiapplicationopensettingsurlstring];

if ([[[UIApplication Sharedapplication]canopenurl:url]) {

[[UIApplication Sharedapplication]openurl:url];

Return

}

else{

if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera])

{

Picker.sourcetype=uiimagepickercontrollersourcetypecamera;

Picker.editing=yes;

Picker.allowsediting=yes;

picker.delegate=self;

[Self Presentviewcontroller:picker animated:yes completion:nil];

}

Else

{

[Self resulthud:@] The camera is not detected! "];

}

}

}];

Uialertaction *libraryaction =[uialertaction actionwithtitle:@ "photo Gallery" Style:uialertactionstyledefault handler:^ ( Uialertaction * _nonnull action) {

Uiimagepickercontroller *picker=[[uiimagepickercontroller Alloc]init];

if (author = = Alauthorizationstatusrestricted | | author = = alauthorizationstatusdenied) {

[Self resulthud:@] Please open your album permissions in the Settings! "];

Nsurl *url = [Nsurl urlwithstring:uiapplicationopensettingsurlstring];

if ([[[UIApplication sharedapplication] Canopenurl:url]) {

[[UIApplication sharedapplication] openurl:url];

//            }

Return

}

else{

if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary])

{

Picker.sourcetype=uiimagepickercontrollersourcetypephotolibrary;

Picker.editing=yes;

Picker.allowsediting=yes;

picker.delegate=self;

[Self Presentviewcontroller:picker animated:yes completion:nil];

}

Else

{

[Self resulthud:@] The gallery is not detected! "];

}

}

}];

Uialertaction *cancleaction=[uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel Handler:nil];

[ALERTVC addaction:libraryaction];

[ALERTVC addaction:cameraaction];

[ALERTVC addaction:cancleaction];

[Self PRESENTVIEWCONTROLLER:ALERTVC animated:yes completion:nil];

}

?? Note: 1, why after opening the gallery or after opening the camera operation, will not return to your original interface: [self PRESENTVIEWCONTROLLER:ALERTVC animated:yes completion:nil];

Because you need to Pickerviewcontroller Dimiss off, Pickerviewcontroller call is implemented through the original controller call present method, so you can use dismiss to close

2, the gray part indicates, directly invokes the application's setting interface, leads the user to open the permission

Second, edit the selected picture and close the image selection controller

-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary< NSString *,id> *) info

{

NSLog (@ "Info--->%@", info);

UIImage *originaimage =[info Objectforkey:uiimagepickercontrollereditedimage];

_headimgview.image=originaimage;

Originaimage=[self imagewithimage:originaimage Scaledtosize:cgsizemake (img_section_height,img_section_height)];

[Self dismissviewcontrolleranimated:yes completion:nil];

}

You can do this, such as uploading images, after you want to borrow the camera to select a picture in the Image editor.

?? Note: The information I printed here is the image selector after the completion of the returned data, according to the printed data you can find that the returned image has two types

1, Uiimagepickercontrollereditedimage 2, Uiimagepickercontrolleroriginaimage

Uiimagepickercontrollereditedimage This is how the picture you select in the image selector is returned in the selection box.

Uiimagepickercontrolleroriginaimage This expression, whether you are in the selection box of the image selector is a method or zoom out, the return is the original picture, without any action.

iOS Red Vest Project Bug Summary (2)

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.