Hey so I am getting the classic EXC_BAD_ACCESS (Code = 1, address = 0x10)
and can't seem to figure out why. I get the error with the following method:
+ (void)logoutWithXId:(NSString *)xId compelationHandler:(void (^)(BOOL))hasSucceeded
{
NSError *error;
// create json object for a users session
NSDictionary *session = [NSDictionary dictionaryWithObjectsAndKeys:
xId, @"x_id",
nil];
NSData *jsonSession = [NSJSONSerialization dataWithJSONObject:session options:NSJSONWritingPrettyPrinted error:&error];
NSString *url = [NSString stringWithFormat:@"%@xsession/logout", potCatURL];
NSURL *URL = [NSURL URLWithString:url];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:URL
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:30.0];
NSString *headerValue = [NSString stringWithFormat:@"Token token=%@", APIToken];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setValue:headerValue forHTTPHeaderField:@"Authorization"];
[request setValue:[NSString stringWithFormat:@"%lu", (unsigned long)[jsonSession length]] forHTTPHeaderField:@"Content-Length"];
[request setHTTPBody:jsonSession];
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error == nil)
{
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
NSInteger statusCode = httpResponse.statusCode;
if (statusCode == 200)
{
//********************* error happens here *******************************
hasSucceeded(true);
}
else
{
hasSucceeded(false);
}
}
else
{
hasSucceeded(false);
}
}];
}
When I call the method like so:
[Xsession logoutWithXId:[userInfo stringForKey:@"x_id"] compelationHandler:nil]
I get the EXC_BAD_ACCESS
error but when I call it like:
[Xsession logoutWithXId:[userInfo stringForKey:@"x_id"] compelationHandler:^(BOOL hasCreated){}]
with an empty compilationHandler it runs fine. Why is this happening, can someone please explain?