Hi guys,
I am using json-framework for communication purposes with certain web service. So far it has served me well. However, this code crashes my adHoc app on the device. The same app in debug mode on the device works ok.
Here is my JSON request(that is where it crashes):
//Make values dictionary
NSMutableDictionary *valuesDictionary;
NSMutableDictionary *valuesDictionary_1;
NSMutableArray *tempArray;
NSMutableArray *values = [[NSMutableArray alloc] init];;
NSEnumerator * enumerator = [self.contactsTempArray objectEnumerator];
id tempObj;
while ( tempObj = [enumerator nextObject] ) {
valuesDictionary = [[NSMutableDictionary alloc] init];
valuesDictionary_1 = [[NSMutableDictionary alloc] init];
tempArray = [[NSMutableArray alloc] init];
//NSString *key = [NSString stringWithFormat:]
if([[tempObj objectForKey:@"Checked"] isEqualToString:@"1"]) {
[valuesDictionary setObject:[NSNumber numberWithInt:[[tempObj objectForKey:@"NotificationContactId"] intValue]] forKey:@"ContactId"];
[valuesDictionary setObject:[NSNumber numberWithBool:true] forKey:@"IsEnabled"];
}
else {
[valuesDictionary setObject:[NSNumber numberWithInt:[[tempObj objectForKey:@"NotificationContactId"] intValue]] forKey:@"ContactId"];
[valuesDictionary setObject:[NSNumber numberWithBool:false] forKey:@"IsEnabled"];
}
[tempArray addObject:valuesDictionary];
[tempArray addObject:valuesDictionary_1];
[values addObject:valuesDictionary];
[valuesDictionary release];
}
//UPDATE NOTIFICATIONS SETTINGS
//JSON POST request
NSArray *keys = [NSArray arrayWithObjects:@"sessionId", @"apiKey", @"deviceToken", @"values", nil];
NSArray *objects = [NSArray arrayWithObjects:appDelegate.sessionId, appDelegate.apiKey, appDelegate.deviceToken, values, nil];
NSDictionary *getAllSensorsDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSString *requestString = [NSString stringWithFormat:@"%@", [getAllSensorsDict JSONFragment], nil];
NSData *requestData = [NSData dataWithBytes: [requestString UTF8String] length: [requestString length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL: [NSURL URLWithString: @"https://xxxxxxxxx"]];
[request setValue:@"application/json;charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[request setHTTPMethod: @"POST"];
[request setHTTPBody: requestData];
//JSON response
NSData *jsonData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
any ideas what am I doing wrong?
Is the JSON request too complex for adHoc?