Add Proxy method
@interface Mineviewcontroller () <uitableviewdelegate, Uitableviewdatasource, Paycelldelegate, Uinavigationcontrollerdelegate, Uiimagepickercontrollerdelegate, uiactionsheetdelegate>
Defining Message Boxes
Uiactionsheet * Act =[[uiactionsheet alloc]initwithtitle:@ "Please select Picture" Delegate:self cancelbuttontitle:@ "Cancel" Destructivebuttontitle:nil otherbuttontitles:@ "Select album", @ "select Camera", Nil];
Show message box
[Act ShowInView:self.view];
message box Proxy implementation
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) buttonindex{
Defining a picture Selector
Uiimagepickercontroller * Picker = [[Uiimagepickercontroller alloc]init];
Judge
Switch (buttonindex) {
Case 0:
Determine if the system allows you to select albums
if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary]) {
Photo Selection is photo album (photo from photo album)
Picker.sourcetype = uiimagepickercontrollersourcetypephotolibrary;
Set up Proxy
picker.delegate=self;
Modal Display interface
[Self Presentviewcontroller:picker animated:yes completion:nil];
}
Break
Case 1://Determine if the system allows the camera to be selected
if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {
Photo Selection is photo album (photo from photo album)
Picker.sourcetype = Uiimagepickercontrollersourcetypecamera;
Set up Proxy
picker.delegate=self;
Modal Display interface
[Self Presentviewcontroller:picker animated:yes completion:nil];
}
else {
NSLog (@ "Camera not supported");
}
Break
Default
Break
}
}
Implementing the picture selector agent
Parameters: Picture Selector dictionary Parameters
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info {
Get to picture with key value
UIImage * Image =info[uiimagepickercontrolleroriginalimage];
NSLog (@ "image=%@ info=%@", image, info);
Determine the type of data source
if (Picker.sourcetype = = uiimagepickercontrollersourcetypephotolibrary) {
Set Picture background
[Usericonbtn setbackgroundimage:image Forstate:uicontrolstatenormal];
Nsuserdefaults * user = [Nsuserdefaults standarduserdefaults];
nsdata* Imgdata = uiimagejpegrepresentation (image, 1);
Isphotochoose = YES;
NSLog (@ "Call this method for the first time");
[User Setobject:imgdata forkey:@ "Saveicon"];
[User Synchronize];
[Self dismissviewcontrolleranimated:yes completion:nil];
}
if (Picker.sourcetype = = Uiimagepickercontrollersourcetypecamera) {
NSLog (@ "Select picture in Camera");
Uiimagewritetosavedphotosalbum (image, nil, nil, nil);
Set Picture background
[Usericonbtn setbackgroundimage:image Forstate:uicontrolstatenormal];
Nsuserdefaults * user = [Nsuserdefaults standarduserdefaults];
nsdata* Imgdata = uiimagejpegrepresentation (image, 1);
Isphotochoose = YES;
NSLog (@ "Call this method for the first time");
[User Setobject:imgdata forkey:@ "Saveicon"];
[User Synchronize];
[Self dismissviewcontrolleranimated:yes completion:nil];
}
}
IOS Dev Call camera and get album photo feature