iOS Uiimagepickercontroller simple Instructions

Source: Internet
Author: User

First, VC add #import <MobileCoreServices/MobileCoreServices.h> Use (NSString *) kuttypeimage defined in it

Decide whether to authorize:

NSString *mediatype = Avmediatypevideo; // Or Avmediatypeaudio Avauthorizationstatus authstatus = [Avcapturedevice authorizationstatusformediatype:mediatype];

avauthorizationstatusnotdetermined = 0,//not explicitly
Avauthorizationstatusrestricted,//Limited
avauthorizationstatusdenied,//not allowed
avauthorizationstatusauthorized//allow

The first method of making a camera:

Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] init];
Add Agent Imagepicker. delegate = self ;
= YES;
= Uiimagepickercontrollersourcetypecamera;
= [[Nsarray alloc] initwithobjects: (NSString *) kuttypeimage, nil];
Jump [self presentmodalviewcontroller:imagepicker animated:yes];

The second use of the camera:

Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] init]; imagepicker. Delegate = = =  uiimagepickercontrollersourcetypecamera;
= [[Nsarray alloc] initwithobjects: (NSString *) Kuttypemovie, nil];
= Uiimagepickercontrollerqualitytypelow; [Self presentmodalviewcontroller:imagepicker animated:yes];

The third Kind uses the photo album to take the picture type:

Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] Init];imagepicker. delegate === =  [[Nsarray alloc] initwithobjects: (NSString *) Kuttypeimage, nil]; [Self presentmodalviewcontroller:imagepicker animated:yes];

The fourth kind uses the album to take the video type:

Uiimagepickercontroller *imagepicker = [[Uiimagepickercontroller alloc] Init];imagepicker. delegate === =  [[Nsarray alloc] initwithobjects: (NSString *) Kuttypemovie, nil]; [Self presentmodalviewcontroller:imagepicker animated:yes];

Agent:

- (void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info{if([[Info Objectforkey:uiimagepickercontrollermediatype] Isequaltostring: (nsstring*) {Kuttypeimage]) {
      Get the original photo         uiimage* original = [Info Objectforkey:uiimagepickercontrollero riginalimage];       //Get pictures of cropped image         uiimage* edit = [Info objectforkey:uiimagepickercontrollereditedimage];       / /Get Picture cropped, the remaining figure         uiimage* crop = [Info objectforkey: uiimagepickercontrollercroprect];       //Get pictures of url         nsurl* url = [Info objectforkey:uiimagepickercontrollermediaurl];        //Get Metadata data information for pictures         nsdictionary* metadata = [info objectforkey:uiimagepickercontrollermediametadata];       //If it's a photo of a photograph, You need to manually save to local, the system does not automatically save photos after successful photo       //uiimagewritetosavedphotosalbum (edit, Self, @ Selector (Image:diDfinishsavingwitherror:contextinfo:), nil);
}Else if([[Info Objectforkey:uiimagepickercontrollermediatype] Isequaltostring: (nsstring*) Kuttypemovie]) {nsstring*videopath =[[Info objectforkey:uiimagepickercontrollermediaurl] path]; Self.filedata=[NSData Datawithcontentsoffile:videopath];
} [Picker Dismissmodalviewcontrolleranimated:yes];}- (void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) Picker {[Picker dismissmodalviewcontrolleranimated:yes];}

iOS uiimagepickercontroller Simple description

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.