ios - Parse 122 error upload -
if save text without having text in field error message in parse.com: update failure - operation couldn't completed(parse error 122.) if press ok , try dismiss view cancel(a button item) app crashes. think valid file name @ parse.com has contain @ least 1 character. maybe can do stop user saving when not enter text? ideas?
this code:
- (ibaction)save:(id)sender { // create pfobject profile information pfuser *profile = [pfuser currentuser]; [profile setobject:nametextfield.text forkey:@"name"]; [profile setobject:titletextfield.text forkey:@"title"]; [profile setobject:locationtextfield.text forkey:@"location"]; // profile image nsdata *imagedata = uiimagejpegrepresentation(profileimageview.image, 0.8); nsstring *filename = [nsstring stringwithformat:@"%@", nametextfield.text]; pffile *imagefile = [pffile filewithname:filename data:imagedata]; [profile setobject:imagefile forkey:@"profileimagefile"]; // show progress mbprogresshud *hud = [mbprogresshud showhudaddedto:self.view animated:yes]; hud.mode = mbprogresshudmodeindeterminate; hud.labeltext = @"updating"; [hud show:yes]; // upload profile parse if(nametextfield.text.length==0 && titletextfield.text.length==0 && locationtextfield.text.length==0) [hud hide:yes]; [profile saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (error) { [[[uialertview alloc] initwithtitle:@"profile information" message:@"fill in atleast 1 field" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]show]; [hud hide:yes]; } else { // show success message uialertview *alert = [[uialertview alloc] initwithtitle:@"" message:@"successfully updated profile" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [alert show]; [hud hide:yes]; [self dismissviewcontrolleranimated:yes completion:nil]; [self performseguewithidentifier:@"profile" sender:self]; } }]; } - (ibaction)cancel:(id)sender { [self dismissviewcontrolleranimated:yes completion:nil]; [self performseguewithidentifier:@"profile" sender:self]; }
1
test if 1 letter theory true. change:
nsstring *filename = [nsstring stringwithformat:@"%@", nametextfield.text];
to:
nsstring *filename = [nsstring stringwithformat:@"file%@", nametextfield.text];
2
or avoid if it's blank. this:
nsstring *filename = [nsstring stringwithformat:@"%@", nametextfield.text]; pffile *imagefile = [pffile filewithname:filename data:imagedata]; [profile setobject:imagefile forkey:@"profileimagefile"];
becomes:
if (nametextfield.text) { nsstring *filename = [nsstring stringwithformat:@"%@", nametextfield.text]; pffile *imagefile = [pffile filewithname:filename data:imagedata]; [profile setobject:imagefile forkey:@"profileimagefile"]; }
3
also, this:
if(nametextfield.text.length==0 && titletextfield.text.length==0 && locationtextfield.text.length==0)
it's doesn't appear connected anything?
4
you call twice in quick succession, , again right after file saves. there in method makes repetitive calls necessary?
[hud hide:yes];
5
your if statement doesn't appear connected anything:
if(nametextfield.text.length==0 && titletextfield.text.length==0 && locationtextfield.text.length==0)
i'm assuming want:
if(nametextfield.text.length==0 && titletextfield.text.length==0 && locationtextfield.text.length==0) { [hud hide:yes]; [profile saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (error) { [[[uialertview alloc] initwithtitle:@"profile information" message:@"fill in atleast 1 field" delegate:nil cancelbuttontitle:@"ok" otherbuttontitles:nil]show]; [hud hide:yes]; } else { // show success message uialertview *alert = [[uialertview alloc] initwithtitle:@"" message:@"successfully updated profile" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil, nil]; [alert show]; [hud hide:yes]; [self dismissviewcontrolleranimated:yes completion:nil]; [self performseguewithidentifier:@"profile" sender:self]; } }]; }
Comments
Post a Comment