From 314e9c992e56966225577bfb05a1c5bb9558d5d4 Mon Sep 17 00:00:00 2001 From: John Fullington Date: Fri, 9 Oct 2015 10:35:03 -0400 Subject: [PATCH] Updated BAAClient.m to avoid crashing! Added code to check for a valid response before serializing the data. Without this code an exception would be thrown if response is nil, in such cases as the server can not be reached. --- BaasBox-iOS-SDK/BAAClient.m | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/BaasBox-iOS-SDK/BAAClient.m b/BaasBox-iOS-SDK/BAAClient.m index 2945143..375f628 100644 --- a/BaasBox-iOS-SDK/BAAClient.m +++ b/BaasBox-iOS-SDK/BAAClient.m @@ -1480,7 +1480,12 @@ - (void)getPath:(NSString *)path [[self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - + + if(response == nil){ + failure(error); + return; + } + NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse*)response; NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions @@ -1530,7 +1535,12 @@ - (void)postPath:(NSString *)path [[self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - + + if(response == nil){ + failure(error); + return; + } + NSHTTPURLResponse *r = (NSHTTPURLResponse*)response; NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions @@ -1570,7 +1580,12 @@ - (void)putPath:(NSString *)path parameters:parameters]; [[self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - + + if(response == nil){ + failure(error); + return; + } + NSHTTPURLResponse *r = (NSHTTPURLResponse*)response; NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions @@ -1610,7 +1625,12 @@ - (void)deletePath:(NSString *)path parameters:parameters]; [[self.session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) { - + + if(response == nil){ + failure(error); + return; + } + NSHTTPURLResponse *r = (NSHTTPURLResponse*)response; NSDictionary *jsonObject = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions