0

I'm trying to get some data sent from my app to a web server.

What the app is supposed to do is display a list of members, show their details when selected and give the ability to edit their details. so far everything except for editing is working.

The error message i'm getting is

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'

The app works fine up until

NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];

It appears that responseData is null. I can't understand it since the url that is generated works fine when entered into the browser.

This is the whole code for the updating details

- (IBAction)submitEdits:(id)sender {
    smdbs_AppData *appData = [smdbs_AppData sharedInstance];
    NSString *loggedInID=appData.loggedInID;

    NSString *member = [self.memberDetailModel objectAtIndex:3];

    NSURL *urlLogin = [NSURL URLWithString:[NSString stringWithFormat:@"http://xxx/API.php?task=setMemberDetails&id=%@&mem_id=%@&section=%@&firstName=%@&lastName=%@&membershipNo=%@&DOB=%@&gender=%@&school=%@&religion=%@&ethnicity=%@&photoPerm=%@&swimPerm=%@&giftaid=%@&giftaidperson=%@&address1=%@&address2=%@&town=%@&county=%@&postCode=%@&homeTelNo=%@&mother=%@&motherMobile=%@&father=%@&fatherMobile=%@&other=%@&relationship=%@&otherTelNo=%@&email1=%@&email2=%@&doctor=%@&surgery=%@&docTelNo=%@&allergiesMed=%@&specialNeeds=%@&pack=%@&six=%@&joinedScouting=%@&joinedBeavers=%@&joinedCubs=%@&joinedScouts=%@&joinedYLs=%@&joinedHelpers=%@&joinedLeaders=%@&crbDate=%@&crbNo=%@", loggedInID, member, self.section.text, self.firstName.text, self.lastName.text, self.membershipNo.text, self.DOB.text, self.gender.text, self.school.text, self.religion.text, self.ethnicity.text, self.photoPerm.text, self.swimPerm.text, self.giftaid.text, self.giftaidperson.text, self.address1.text, self.address2.text, self.town.text, self.county.text, self.postCode.text, self.homeTelNo.text, self.mother.text, self.motherMobile.text, self.father.text, self.fatherMobile.text, self.other.text, self.relationship.text, self.otherTelNo.text, self.email1.text, self.email2.text, self.doctor.text, self.surgery.text, self.docTelNo.text, self.allergiesMed.text, self.specialNeeds.text, self.pack.text, self.six.text, self.joinedScouting.text, self.joinedBeavers.text, self.joinedCubs.text, self.joinedScouts.text, self.joinedYLs.text, self.joinedHelpers.text, self.joinedLeaders.text, self.crbDate.text, self.crbNo.text]];

    dispatch_async(kBgQueue, ^{
        NSData* editData = [NSData dataWithContentsOfURL:urlLogin];
        [self performSelectorOnMainThread:@selector(EditData:)
                               withObject:editData waitUntilDone:YES];
    });
}

- (void)EditData:(NSData *)responseData
{
    NSError* error;
    NSLog(@"%@",responseData);
    NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData options:kNilOptions error:&error];
    NSString* success =  [json objectForKey:@"success"];

    if ([success isEqualToString:@"1"]) {
        [self performSegueWithIdentifier:@"showMemberDetails" sender:nil];
    }
}
Alladinian
  • 34,483
  • 6
  • 89
  • 91
Ceri Turner
  • 830
  • 2
  • 12
  • 36
  • You are not catching any errors while downloading data. Use sendSynchronousRequest class method of NSURLConnection instead `+ (NSData *)sendSynchronousRequest:(NSURLRequest *)request returningResponse:(NSURLResponse **)response error:(NSError **)error` and log the error to see why is it failing. – 0x8badf00d May 28 '12 at 14:39
  • I'm getting the message "Error Domain=NSURLErrorDomain Code=-1000 "bad URL" UserInfo=0x6866740 {NSUnderlyingError=0x68694c0 "bad URL", NSLocalizedDescription=bad URL}" – Ceri Turner May 28 '12 at 15:48
  • You need to encode the URL. That might be the problem. – 0x8badf00d May 28 '12 at 17:34
  • How would i go about doing that? I'm relatively new to iOS development – Ceri Turner May 28 '12 at 17:37
  • 1
    Take out the URL string from NSURL and then use NSString method stringByAddingPercentEscapesUsingEncoding: to encode that URL string then pass it to NSURL. – 0x8badf00d May 28 '12 at 17:46
  • Thanks, that seems to have solved it – Ceri Turner May 28 '12 at 18:14

0 Answers0