ios - Saving pictures to parse -


my project save data parse , while can pick image library cannot open camera. found tutorial not compatible code. link tutorial here: tutorial . using .storyboard , tutorial .xib, not know if change anything.

my .m file here:

#import "newrecipeviewcontroller.h" #import <mobilecoreservices/utcoretypes.h> #import <parse/parse.h> #import "mbprogresshud.h"  @interface newrecipeviewcontroller () - (ibaction)save:(id)sender; - (ibaction)cancel:(id)sender; @property (weak, nonatomic) iboutlet uiimageview *recipeimageview; @property (weak, nonatomic) iboutlet uitextfield *nametextfield; @property (weak, nonatomic) iboutlet uitextfield *preptimetextfield; @property (weak, nonatomic) iboutlet uitextfield *ingredientstextfield;  @end  @implementation newrecipeviewcontroller  - (id)initwithstyle:(uitableviewstyle)style {     self = [super initwithstyle:style];     if (self) {         // custom initialization     }     return self; }  - (void)viewdidload {     [super viewdidload];      _nametextfield.delegate = self;     _preptimetextfield.delegate = self;     _ingredientstextfield.delegate = self;  }  - (void)didreceivememorywarning {     [super didreceivememorywarning];     // dispose of resources can recreated. }  #pragma mark - table view delegate  - (void)tableview:(uitableview *)tableview didselectrowatindexpath:(nsindexpath *)indexpath {     if (indexpath.row == 0) {         [self showphotolibary];     } }   - (void)showphotolibary {     if (([uiimagepickercontroller issourcetypeavailable:           uiimagepickercontrollersourcetypesavedphotosalbum] == no)) {         return;     }      uiimagepickercontroller *mediaui = [[uiimagepickercontroller alloc] init];     mediaui.sourcetype = uiimagepickercontrollersourcetypephotolibrary;      // displays saved pictures camera roll album.     mediaui.mediatypes = @[(nsstring*)kuttypeimage];      // hides controls moving & scaling pictures     mediaui.allowsediting = no;      mediaui.delegate = self;      [self.navigationcontroller presentmodalviewcontroller: mediaui animated: yes]; }  - (ibaction)save:(id)sender {     // create pfobject recipe information     pfobject *recipe = [pfobject objectwithclassname:@"recipe"];     [recipe setobject:_nametextfield.text forkey:@"name"];     [recipe setobject:_preptimetextfield.text forkey:@"preptime"];      nsarray *ingredients = [_ingredientstextfield.text componentsseparatedbystring: @","];     [recipe setobject:ingredients forkey:@"ingredients"];      // recipe image     nsdata *imagedata = uiimagejpegrepresentation(_recipeimageview.image, 0.8);     nsstring *filename = [nsstring stringwithformat:@"%@.png", _nametextfield.text];     pffile *imagefile = [pffile filewithname:filename data:imagedata];     [recipe setobject:imagefile forkey:@"imagefile"];      // show progress     mbprogresshud *hud = [mbprogresshud showhudaddedto:self.view animated:yes];     hud.mode = mbprogresshudmodeindeterminate;     hud.labeltext = @"uploading";     [hud show:yes];      // upload recipe parse     [recipe saveinbackgroundwithblock:^(bool succeeded, nserror *error) {         [hud hide:yes];          if (!error) {             // show success message             uialertview *alert = [[uialertview alloc] initwithtitle:@"upload complete" message:@"successfully saved recipe" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil, nil];             [alert show];              // notify table view reload recipes parse cloud             [[nsnotificationcenter defaultcenter] postnotificationname:@"refreshtable" object:self];              // dismiss controller             [self dismissviewcontrolleranimated:yes completion:nil];          } else {             uialertview *alert = [[uialertview alloc] initwithtitle:@"upload failure" message:[error localizeddescription] delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil];             [alert show];          }      }]; }  - (ibaction)cancel:(id)sender {     [self dismissviewcontrolleranimated:yes completion:nil]; }  - (void)viewdidunload {     [self setrecipeimageview:nil];     [self setnametextfield:nil];     [self setpreptimetextfield:nil];     [self setingredientstextfield:nil];     [super viewdidunload]; }   - (void) imagepickercontroller: (uiimagepickercontroller *) picker didfinishpickingmediawithinfo: (nsdictionary *) info {      uiimage *originalimage = (uiimage *) [info objectforkey:uiimagepickercontrolleroriginalimage];     self.recipeimageview.image = originalimage;      [picker dismissviewcontrolleranimated:yes completion:nil];  }  #pragma mark - textfield delegate  - (bool)textfieldshouldreturn:(uitextfield *)textfield {     [textfield resignfirstresponder];     return yes; }  - (ibaction)takephoto:(id)sender {     uiimagepickercontroller *picker = [[uiimagepickercontroller alloc] init];     picker.delegate = self;     picker.allowsediting = yes;     picker.sourcetype = uiimagepickercontrollersourcetypecamera;      [self presentviewcontroller:picker animated:yes completion:null]; }  - (ibaction)selectphoto:(id)sender {     uiimagepickercontroller *picker = [[uiimagepickercontroller alloc] init];     picker.delegate = self;     picker.allowsediting = yes;     picker.sourcetype = uiimagepickercontrollersourcetypephotolibrary;      [self presentviewcontroller:picker animated:yes completion:null];  } @end 

any appreciated.

take @ apple's provided sample project (especially aplviewcontroller.m)

https://developer.apple.com/library/ios/samplecode/photopicker/introduction/intro.html#//apple_ref/doc/uid/dts40010196

you'll see them following 4 steps. doing last half of step one, without first verifying if source type available.

from uiimagepickercontroller class reference:

to use image picker controller containing default controls, perform these steps:

verify device capable of picking content desired source. calling issourcetypeavailable: class method, providing constant “uiimagepickercontrollersourcetype” enumeration.  check media types available, source type you’re using, calling availablemediatypesforsourcetype: class method. lets distinguish between camera can used video recording , 1 can used still images.  tell image picker controller adjust ui according media types want make available—still images, movies, or both—by setting mediatypes property.  present user interface. on iphone or ipod touch, modally (full-screen) calling presentviewcontroller:animated:completion: method of active view controller, passing configured image picker controller new view controller. 

Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -