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