0

I am pretty new to objective C. Started working with callbacks using NSURLSession. The application runs perfect on device.But the simulator gives some errors.

I am trying to do a POST and have a delegate which informs the caller when the response is received. I am able to get the expected data and it does not break my application. But, when I step through the instructions using the lldb debugger, it gives me a EXC BAD ACCESS and the error code changes for different simulators. This is the instruction and error. on iPhone 5 simulator and this is the instruction and error on iPhone 6 simulator. Below is the code for the call back.

NSData *postData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
NSString *postLength = [NSString stringWithFormat:@"%lu",(unsigned long)[postData length]];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];

[request setHTTPBody:postData];

NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];

// Send the request to the server
NSURLSessionDataTask *dataTask=[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error){

    [self.delegate sendStatus:@"FetchCompleted!"];
}];

[dataTask resume];

My scheme is zombie enabled, and it did not log any zombie objects. I am pretty sure that the code above is the root cause of the error as I have tried to debug with commenting it and it works fine. Any help would be appreciated. Attached below below is the stack trace. Thanks!

0 Answers0