Browse files

Merge branch 'merge_foundation_json' of github.com:seatme/AFNetworking

Conflicts:
	AFNetworking/AFHTTPClient.m
	AFNetworking/AFHTTPRequestOperation.m
	AFNetworking/AFJSONRequestOperation.m
	AFNetworking/AFXMLRequestOperation.m
	AFNetworking/NSString+AFNetworking.h
	Example/Classes/AFGowallaAPIClient.h
	Mac Example/AppDelegate.h
	Mac Example/AppDelegate.m
	Mac Example/Classes/AFGowallaAPIClient.h
	iOS Example/Classes/AFGowallaAPIClient.h
  • Loading branch information...
2 parents 810096b + ef5bf73 commit 521fd35477fe598434ba009c71fe5271a771e4ac @zbowling zbowling committed Oct 18, 2011
Showing with 41 additions and 25 deletions.
  1. +17 −12 AFNetworking/AFHTTPClient.m
  2. +1 −1 AFNetworking/AFHTTPRequestOperation.m
  3. +23 −12 AFNetworking/AFJSONRequestOperation.m
View
29 AFNetworking/AFHTTPClient.m
@@ -31,7 +31,17 @@
#import <UIKit/UIKit.h>
#endif
+#ifndef USE_FOUNDATION_JSON
+#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 || __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6
+#define USE_FOUNDATION_JSON 1
+#else
+#define USE_FOUNDATION_JSON 0
+#endif
+#endif
+
+#if !USE_FOUNDATION_JSON
#import "JSONKit.h"
+#endif
static NSString * const kAFMultipartFormLineDelimiter = @"\r\n"; // CRLF
static NSString * const kAFMultipartFormBoundary = @"Boundary+0xAbCdEfGbOuNdArY";
@@ -82,12 +92,11 @@ - (id)initWithStringEncoding:(NSStringEncoding)encoding;
}
static NSURL * AFURLWithPathRelativeToURL(NSString *path, NSURL *baseURL) {
- NSURL *url = [baseURL URLByAppendingPathComponent:[path stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"/"]]];
- NSString *URLString = [url absoluteString];
+ NSString *URLString = [[baseURL absoluteString] stringByAppendingPathComponent:path];
if ([path hasSuffix:@"/"]) {
URLString = [URLString stringByAppendingString:@"/"];
}
-
+
return [NSURL URLWithString:URLString];
}
@@ -110,15 +119,11 @@ - (id)initWithStringEncoding:(NSStringEncoding)encoding;
static NSString * AFJSONStringFromParameters(NSDictionary *parameters) {
NSString *JSONString = nil;
-#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 || __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6
- if ([NSJSONSerialization class]) {
- NSError *error = nil;
- NSData *JSONData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];
- if (!error) {
- JSONString = [[[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding] autorelease];
- }
- } else {
- JSONString = [parameters JSONString];
+#if USE_FOUNDATION_JSON
+ NSError *error = nil;
+ NSData *JSONData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];
+ if (!error) {
+ JSONString = [[[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding] autorelease];
}
#else
JSONString = [parameters JSONString];
View
2 AFNetworking/AFHTTPRequestOperation.m
@@ -70,7 +70,7 @@ - (NSError *)error {
}
}
- return _HTTPError;
+ return [super error];
}
- (BOOL)hasAcceptableStatusCode {
View
35 AFNetworking/AFJSONRequestOperation.m
@@ -24,7 +24,20 @@
#include <Availability.h>
+#ifndef USE_FOUNDATION_JSON
+#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 || __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6
+#define USE_FOUNDATION_JSON 1
+#else
+#define USE_FOUNDATION_JSON 0
+#endif
+#endif
+
+#if !USE_FOUNDATION_JSON
#import "JSONKit.h"
+#endif
+
+
+
static dispatch_queue_t af_json_request_operation_processing_queue;
static dispatch_queue_t json_request_operation_processing_queue() {
@@ -64,10 +77,14 @@ + (AFJSONRequestOperation *)JSONRequestOperationWithRequest:(NSURLRequest *)urlR
});
}
} else {
+ __block dispatch_queue_t caller_queue = dispatch_get_current_queue();
+ dispatch_retain(caller_queue); //retain calling queue
dispatch_async(json_request_operation_processing_queue(), ^(void) {
+ NSError *error = nil;
id JSON = operation.responseJSON;
+ operation.error = error;
- dispatch_async(dispatch_get_main_queue(), ^(void) {
+ dispatch_sync(caller_queue, ^(void) {
if (operation.error) {
if (failure) {
failure(operation.request, operation.response, operation.error);
@@ -117,19 +134,13 @@ - (id)responseJSON {
if ([self.responseData length] == 0) {
self.responseJSON = nil;
} else {
-
-#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_4_3 || __MAC_OS_X_VERSION_MIN_REQUIRED > __MAC_10_6
- if ([NSJSONSerialization class]) {
- self.responseJSON = [NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error];
- } else {
- self.responseJSON = [[JSONDecoder decoder] objectWithData:self.responseData error:&error];
- }
-#else
+ #if USE_FOUNDATION_JSON
+ self.responseJSON = [NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error];
+ #else
self.responseJSON = [[JSONDecoder decoder] objectWithData:self.responseData error:&error];
-#endif
+ #endif
+ self.error = error;
}
-
- self.error = error;
}
return _responseJSON;

0 comments on commit 521fd35

Please sign in to comment.