Set up the head agent
<uinavigationcontrollerdelegate, uiimagepickercontrollerdelegate>
1. Calling the camera
Detect if a front-facing camera is available
- (BOOL) isfrontcameraavailable{ return [Uiimagepickercontroller iscameradeviceavailable : Uiimagepickercontrollercameradevicefront];}
Detect if the rear camera is available
- (BOOL) isrearcameraavailable{ return [Uiimagepickercontroller iscameradeviceavailable: Uiimagepickercontrollercameradevicerear];}
Call camera
///Call Camera- (void) persentimagepicker{if(!_imagepickerg) { ///Initializing the camera_imagepickerg =[[Uiimagepickercontroller alloc]init]; ///Agent_imagepickerg.Delegate=Self ; } //whether the front camera is available if([self isfrontcameraavailable]) {_imagepickerg.sourcetype=Uiimagepickercontrollersourcetypecamera; } //whether the rear camera is available Else if([self isfirstresponder]) {_imagepickerg.sourcetype=Uiimagepickercontrollersourcetypecamera; } Else{[Svprogresshud showerrorwithstatus:@"no camera available ~"]; return; } ///allow cropping after taking pictures_imagepickerg.allowsediting =YES; [Self.navigationcontroller Presentviewcontroller:_imagepickerg Animated:yes completion:nil];}
2. Call Album
///calling a local album- (void) persentimagepicker{if(!_imagepickerg) { ///Initializing the camera_imagepickerg =[[Uiimagepickercontroller alloc]init]; ///Agent_imagepickerg.Delegate=Self ; } ///albums_imagepickerg.sourcetype =uiimagepickercontrollersourcetypephotolibrary;_imagepickerg.allowsediting=YES; [Self.navigationcontroller Presentviewcontroller:_imagepickerg Animated:yes completion:nil];}
3. Agent Events
/// deselect picture (take photo)-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{ [ Picker Dismissviewcontrolleranimated:yes Completion:nil];}
/// Select the picture to complete (from the album or take a photo)-(void) Imagepickercontroller: (Uiimagepickercontroller *) picker Didfinishpickingmediawithinfo: (nsdictionary<nsstring *,ID> *) info{ *image = [Info objectforkey:uiimagepickercontrolleroriginalimage];///original //Get the picture after trimming UIImage *imageup = [info objectforkey:uiimagepickercontrollereditedimage]; }
4. Save the picture to a local
/// Save picture to local album -(void) Imagetopicsave: (UIImage *) image{ uiimagewritetosavedphotosalbum (image , Self, @selector (image:didFinishSavingWithError:contextInfo:), nil);} -(void) Image: (UIImage *) image didfinishsavingwitherror: (nserror *) error contextinfo: (void *) contextinfo{ if (Error = = nil) { }else{ // the picture could not be saved locally }}
iOS dev-ios call camera call album "Save picture to local album"