ios - Terminating App - NSInvalidArgumentException -
crashing when running parse anypic code.
-(void)sendcommentbutton:(id) sender { nsstring *trimmedcomment = [commenttextview.text stringbytrimmingcharactersinset:[nscharacterset whitespacecharacterset]]; if (trimmedcomment.length != 0 && [self.photo objectforkey:kpapphotouserkey]) { pfobject *comment = [pfobject objectwithclassname:kpapactivityclasskey]; [comment setobject:trimmedcomment forkey:kpapactivitycontentkey]; // set comment text [comment setobject:[self.photo objectforkey:kpapphotouserkey] forkey:kpapactivitytouserkey]; // set touser [comment setobject:[pfuser currentuser] forkey:kpapactivityfromuserkey]; // set fromuser [comment setobject:kpapactivitytypecomment forkey:kpapactivitytypekey]; [comment setobject:self.photo forkey:kpapactivityphotokey]; [comment setobject:self.photofile forkey:@"attachmentfile"]; pfacl *acl = [pfacl aclwithuser:[pfuser currentuser]]; [acl setpublicreadaccess:yes]; [acl setwriteaccess:yes foruser:[self.photo objectforkey:kpapphotouserkey]]; comment.acl = acl; [[papcache sharedcache] incrementcommentcountforphoto:self.photo]; // show hud view [mbprogresshud showhudaddedto:self.view.superview animated:yes]; // if more 5 seconds pass since post comment, stop waiting server respond nstimer *timer = [nstimer scheduledtimerwithtimeinterval:5.0f target:self selector:@selector(handlecommenttimeout:) userinfo:@{@"comment": comment} repeats:no]; [comment saveeventually:^(bool succeeded, nserror *error) { [timer invalidate]; if (error && error.code == kpferrorobjectnotfound) { [[papcache sharedcache] decrementcommentcountforphoto:self.photo]; uialertview *alert = [[uialertview alloc] initwithtitle:nslocalizedstring(@"could not post comment", nil) message:nslocalizedstring(@"this photo no longer available", nil) delegate:nil cancelbuttontitle:nil otherbuttontitles:@"ok", nil]; [alert show]; [self.navigationcontroller popviewcontrolleranimated:yes]; } [[nsnotificationcenter defaultcenter] postnotificationname:papphotodetailsviewcontrollerusercommentedonphotonotification object:self.photo userinfo:@{@"comments": @(self.objects.count + 1)}]; [mbprogresshud hidehudforview:self.view.superview animated:yes]; [self loadobjects]; }]; } [self.commenttextview settext:@""]; [self.commenttextview resignfirstresponder]; if (self.photofile != nil) { self.photofile = nil; } } picking image
- (void)imagepickercontroller:(uiimagepickercontroller *)picker didfinishpickingmediawithinfo:(nsdictionary *)info { nslog(@"hello"); uiimage *img = [info objectforkey:uiimagepickercontrolleroriginalimage]; // jpeg decrease file size , enable faster uploads & downloads nsdata *imagedata = uiimagejpegrepresentation(img, 0.8f); self.photofile = [pffile filewithdata:imagedata]; // request background execution task allow finish uploading photo if app backgrounded self.fileuploadbackgroundtaskid = [[uiapplication sharedapplication] beginbackgroundtaskwithexpirationhandler:^{ [[uiapplication sharedapplication] endbackgroundtask:self.fileuploadbackgroundtaskid]; }]; nslog(@"requested background expiration task id %lu anypic photo upload", (unsigned long)self.fileuploadbackgroundtaskid); [self.photofile saveinbackgroundwithblock:^(bool succeeded, nserror *error) { if (succeeded) { nslog(@"photo uploaded successfully"); uialertview *alert = [[uialertview alloc] initwithtitle:@"photo uploaded" message:@"successfully" delegate:self cancelbuttontitle:@"ok" otherbuttontitles:nil]; [alert show]; } else { [[uiapplication sharedapplication] endbackgroundtask:self.fileuploadbackgroundtaskid]; } }]; [self dismissviewcontrolleranimated:yes completion:nil]; } 
question: why crashing? believe code crashing it. did crash not add attachmentfile , put comment.
if need more code or need clarifications please comment down below
pfobject *comment = [pfobject objectwithclassname:kpapactivityclasskey]; [comment setobject:trimmedcomment forkey:kpapactivitycontentkey]; // set comment text [comment setobject:[self.photo objectforkey:kpapphotouserkey] forkey:kpapactivitytouserkey]; // set touser [comment setobject:[pfuser currentuser] forkey:kpapactivityfromuserkey]; // set fromuser [comment setobject:kpapactivitytypecomment forkey:kpapactivitytypekey]; [comment setobject:self.photo forkey:kpapactivityphotokey]; [comment setobject:self.photofile forkey:@"attachmentfile"]; in 1 of these lines, you're passing nil first parameter of setobject:forkey. add exception breakpoint (in breakpoints tab of left sidebar) , check line breaks on.
Comments
Post a Comment