IOS Dev Call camera and get album photo feature

Source: Internet
Author: User

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

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.