From 1cfa4059577e173488457fc5eec95098115fda13 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 08:50:32 -0700 Subject: [PATCH 01/81] Removing AFJSONUtilities in favor of just using NSJSONSerialization --- AFNetworking/AFHTTPClient.m | 3 +- AFNetworking/AFJSONRequestOperation.m | 3 +- AFNetworking/AFJSONUtilities.h | 26 --- AFNetworking/AFJSONUtilities.m | 217 ------------------ .../project.pbxproj | 6 - .../project.pbxproj | 6 - 6 files changed, 2 insertions(+), 259 deletions(-) delete mode 100644 AFNetworking/AFJSONUtilities.h delete mode 100644 AFNetworking/AFJSONUtilities.m diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index b116f3c..fa03444 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -24,7 +24,6 @@ #import "AFHTTPClient.h" #import "AFHTTPRequestOperation.h" -#import "AFJSONUtilities.h" #import @@ -195,7 +194,7 @@ NSArray * AFQueryStringComponentsFromKeyAndArrayValue(NSString *key, NSArray *va static NSString * AFJSONStringFromParameters(NSDictionary *parameters) { NSError *error = nil; - NSData *JSONData = AFJSONEncode(parameters, &error); + NSData *JSONData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];; if (!error) { return [[[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding] autorelease]; diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index bcdcb7f..133293b 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -21,7 +21,6 @@ // THE SOFTWARE. #import "AFJSONRequestOperation.h" -#import "AFJSONUtilities.h" static dispatch_queue_t af_json_request_operation_processing_queue; static dispatch_queue_t json_request_operation_processing_queue() { @@ -72,7 +71,7 @@ static dispatch_queue_t json_request_operation_processing_queue() { if ([self.responseData length] == 0) { self.responseJSON = nil; } else { - self.responseJSON = AFJSONDecode(self.responseData, &error); + self.responseJSON = [NSJSONSerialization JSONObjectWithData:self.responseData options:0 error:&error]; } self.JSONError = error; diff --git a/AFNetworking/AFJSONUtilities.h b/AFNetworking/AFJSONUtilities.h deleted file mode 100644 index ece26a0..0000000 --- a/AFNetworking/AFJSONUtilities.h +++ /dev/null @@ -1,26 +0,0 @@ -// AFJSONUtilities.h -// -// Copyright (c) 2011 Gowalla (http://gowalla.com/) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import - -extern NSData * AFJSONEncode(id object, NSError **error); -extern id AFJSONDecode(NSData *data, NSError **error); diff --git a/AFNetworking/AFJSONUtilities.m b/AFNetworking/AFJSONUtilities.m deleted file mode 100644 index 3377fc4..0000000 --- a/AFNetworking/AFJSONUtilities.m +++ /dev/null @@ -1,217 +0,0 @@ -// AFJSONUtilities.m -// -// Copyright (c) 2011 Gowalla (http://gowalla.com/) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. - -#import "AFJSONUtilities.h" - -NSData * AFJSONEncode(id object, NSError **error) { - NSData *data = nil; - - SEL _JSONKitSelector = NSSelectorFromString(@"JSONDataWithOptions:error:"); - SEL _YAJLSelector = NSSelectorFromString(@"yajl_JSONString"); - - id _SBJsonWriterClass = NSClassFromString(@"SBJsonWriter"); - SEL _SBJsonWriterSelector = NSSelectorFromString(@"dataWithObject:"); - - id _NXJsonSerializerClass = NSClassFromString(@"NXJsonSerializer"); - SEL _NXJsonSerializerSelector = NSSelectorFromString(@"serialize:"); - - id _NSJSONSerializationClass = NSClassFromString(@"NSJSONSerialization"); - SEL _NSJSONSerializationSelector = NSSelectorFromString(@"dataWithJSONObject:options:error:"); - -#ifdef _AFNETWORKING_PREFER_NSJSONSERIALIZATION_ - if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) { - goto _af_nsjson_encode; - } -#endif - - if (_JSONKitSelector && [object respondsToSelector:_JSONKitSelector]) { - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[object methodSignatureForSelector:_JSONKitSelector]]; - invocation.target = object; - invocation.selector = _JSONKitSelector; - - NSUInteger serializeOptionFlags = 0; - [invocation setArgument:&serializeOptionFlags atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - if (error != NULL) { - [invocation setArgument:error atIndex:3]; - } - - [invocation invoke]; - [invocation getReturnValue:&data]; - } else if (_SBJsonWriterClass && [_SBJsonWriterClass instancesRespondToSelector:_SBJsonWriterSelector]) { - id writer = [[_SBJsonWriterClass alloc] init]; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[writer methodSignatureForSelector:_SBJsonWriterSelector]]; - invocation.target = writer; - invocation.selector = _SBJsonWriterSelector; - - [invocation setArgument:&object atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - - [invocation invoke]; - [invocation getReturnValue:&data]; - [writer release]; - } else if (_YAJLSelector && [object respondsToSelector:_YAJLSelector]) { - @try { - NSString *JSONString = nil; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[object methodSignatureForSelector:_YAJLSelector]]; - invocation.target = object; - invocation.selector = _YAJLSelector; - - [invocation invoke]; - [invocation getReturnValue:&JSONString]; - - data = [JSONString dataUsingEncoding:NSUTF8StringEncoding]; - } - @catch (NSException *exception) { - *error = [[[NSError alloc] initWithDomain:NSStringFromClass([exception class]) code:0 userInfo:[exception userInfo]] autorelease]; - } - } else if (_NXJsonSerializerClass && [_NXJsonSerializerClass respondsToSelector:_NXJsonSerializerSelector]) { - NSString *JSONString = nil; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[_NXJsonSerializerClass methodSignatureForSelector:_NXJsonSerializerSelector]]; - invocation.target = _NXJsonSerializerClass; - invocation.selector = _NXJsonSerializerSelector; - - [invocation setArgument:&object atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - - [invocation invoke]; - [invocation getReturnValue:&JSONString]; - data = [JSONString dataUsingEncoding:NSUTF8StringEncoding]; - } else if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) { -#ifdef _AFNETWORKING_PREFER_NSJSONSERIALIZATION_ - _af_nsjson_encode:; -#endif - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[_NSJSONSerializationClass methodSignatureForSelector:_NSJSONSerializationSelector]]; - invocation.target = _NSJSONSerializationClass; - invocation.selector = _NSJSONSerializationSelector; - - [invocation setArgument:&object atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - NSUInteger writeOptions = 0; - [invocation setArgument:&writeOptions atIndex:3]; - if (error != NULL) { - [invocation setArgument:error atIndex:4]; - } - - [invocation invoke]; - [invocation getReturnValue:&data]; - } else { - NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedString(@"Please either target a platform that supports NSJSONSerialization or add one of the following libraries to your project: JSONKit, SBJSON, or YAJL", nil) forKey:NSLocalizedRecoverySuggestionErrorKey]; - [[NSException exceptionWithName:NSInternalInconsistencyException reason:NSLocalizedString(@"No JSON generation functionality available", nil) userInfo:userInfo] raise]; - } - - return data; -} - -id AFJSONDecode(NSData *data, NSError **error) { - id JSON = nil; - - SEL _JSONKitSelector = NSSelectorFromString(@"objectFromJSONDataWithParseOptions:error:"); - SEL _YAJLSelector = NSSelectorFromString(@"yajl_JSONWithOptions:error:"); - - id _SBJSONParserClass = NSClassFromString(@"SBJsonParser"); - SEL _SBJSONParserSelector = NSSelectorFromString(@"objectWithData:"); - - id _NSJSONSerializationClass = NSClassFromString(@"NSJSONSerialization"); - SEL _NSJSONSerializationSelector = NSSelectorFromString(@"JSONObjectWithData:options:error:"); - - id _NXJsonParserClass = NSClassFromString(@"NXJsonParser"); - SEL _NXJsonParserSelector = NSSelectorFromString(@"parseData:error:ignoreNulls:"); - - -#ifdef _AFNETWORKING_PREFER_NSJSONSERIALIZATION_ - if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) { - goto _af_nsjson_decode; - } -#endif - - if (_JSONKitSelector && [data respondsToSelector:_JSONKitSelector]) { - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[data methodSignatureForSelector:_JSONKitSelector]]; - invocation.target = data; - invocation.selector = _JSONKitSelector; - - NSUInteger parseOptionFlags = 0; - [invocation setArgument:&parseOptionFlags atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - if (error != NULL) { - [invocation setArgument:&error atIndex:3]; - } - - [invocation invoke]; - [invocation getReturnValue:&JSON]; - } else if (_SBJSONParserClass && [_SBJSONParserClass instancesRespondToSelector:_SBJSONParserSelector]) { - id parser = [[_SBJSONParserClass alloc] init]; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[parser methodSignatureForSelector:_SBJSONParserSelector]]; - invocation.target = parser; - invocation.selector = _SBJSONParserSelector; - - [invocation setArgument:&data atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - - [invocation invoke]; - [invocation getReturnValue:&JSON]; - [parser release]; - } else if (_YAJLSelector && [data respondsToSelector:_YAJLSelector]) { - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[data methodSignatureForSelector:_YAJLSelector]]; - invocation.target = data; - invocation.selector = _YAJLSelector; - - NSUInteger yajlParserOptions = 0; - [invocation setArgument:&yajlParserOptions atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - if (error != NULL) { - [invocation setArgument:&error atIndex:3]; - } - - [invocation invoke]; - [invocation getReturnValue:&JSON]; - } else if (_NXJsonParserClass && [_NXJsonParserClass respondsToSelector:_NXJsonParserSelector]) { - NSNumber *nullOption = [NSNumber numberWithBool:YES]; - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[_NXJsonParserClass methodSignatureForSelector:_NXJsonParserSelector]]; - invocation.target = _NXJsonParserClass; - invocation.selector = _NXJsonParserSelector; - - [invocation setArgument:&data atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - if (error != NULL) { - [invocation setArgument:&error atIndex:3]; - } - [invocation setArgument:&nullOption atIndex:4]; - - [invocation invoke]; - [invocation getReturnValue:&JSON]; - } else if (_NSJSONSerializationClass && [_NSJSONSerializationClass respondsToSelector:_NSJSONSerializationSelector]) { -#ifdef _AFNETWORKING_PREFER_NSJSONSERIALIZATION_ - _af_nsjson_decode:; -#endif - NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[_NSJSONSerializationClass methodSignatureForSelector:_NSJSONSerializationSelector]]; - invocation.target = _NSJSONSerializationClass; - invocation.selector = _NSJSONSerializationSelector; - - [invocation setArgument:&data atIndex:2]; // arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation - NSUInteger readOptions = 0; - [invocation setArgument:&readOptions atIndex:3]; - if (error != NULL) { - [invocation setArgument:&error atIndex:4]; - } - - [invocation invoke]; - [invocation getReturnValue:&JSON]; - } else { - NSDictionary *userInfo = [NSDictionary dictionaryWithObject:NSLocalizedString(@"Please either target a platform that supports NSJSONSerialization or add one of the following libraries to your project: JSONKit, SBJSON, or YAJL", nil) forKey:NSLocalizedRecoverySuggestionErrorKey]; - [[NSException exceptionWithName:NSInternalInconsistencyException reason:NSLocalizedString(@"No JSON parsing functionality available", nil) userInfo:userInfo] raise]; - } - - return JSON; -} diff --git a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj index fd75074..e537260 100644 --- a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj @@ -15,7 +15,6 @@ F8129C641591090B009BFE23 /* AFHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C511591090B009BFE23 /* AFHTTPRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8129C651591090B009BFE23 /* AFImageRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C531591090B009BFE23 /* AFImageRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8129C661591090B009BFE23 /* AFJSONRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C551591090B009BFE23 /* AFJSONRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C671591090B009BFE23 /* AFJSONUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C571591090B009BFE23 /* AFJSONUtilities.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8129C681591090B009BFE23 /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C591591090B009BFE23 /* AFNetworkActivityIndicatorManager.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8129C691591090B009BFE23 /* AFPropertyListRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C5C1591090B009BFE23 /* AFPropertyListRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8129C6A1591090B009BFE23 /* AFURLConnectionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C5E1591090B009BFE23 /* AFURLConnectionOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; @@ -46,8 +45,6 @@ F8129C531591090B009BFE23 /* AFImageRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFImageRequestOperation.m; path = ../AFNetworking/AFImageRequestOperation.m; sourceTree = ""; }; F8129C541591090B009BFE23 /* AFJSONRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFJSONRequestOperation.h; path = ../AFNetworking/AFJSONRequestOperation.h; sourceTree = ""; }; F8129C551591090B009BFE23 /* AFJSONRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFJSONRequestOperation.m; path = ../AFNetworking/AFJSONRequestOperation.m; sourceTree = ""; }; - F8129C561591090B009BFE23 /* AFJSONUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFJSONUtilities.h; path = ../AFNetworking/AFJSONUtilities.h; sourceTree = ""; }; - F8129C571591090B009BFE23 /* AFJSONUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFJSONUtilities.m; path = ../AFNetworking/AFJSONUtilities.m; sourceTree = ""; }; F8129C581591090B009BFE23 /* AFNetworkActivityIndicatorManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFNetworkActivityIndicatorManager.h; path = ../AFNetworking/AFNetworkActivityIndicatorManager.h; sourceTree = ""; }; F8129C591591090B009BFE23 /* AFNetworkActivityIndicatorManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFNetworkActivityIndicatorManager.m; path = ../AFNetworking/AFNetworkActivityIndicatorManager.m; sourceTree = ""; }; F8129C5A1591090B009BFE23 /* AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFNetworking.h; path = ../AFNetworking/AFNetworking.h; sourceTree = ""; }; @@ -160,8 +157,6 @@ F8129C531591090B009BFE23 /* AFImageRequestOperation.m */, F8129C541591090B009BFE23 /* AFJSONRequestOperation.h */, F8129C551591090B009BFE23 /* AFJSONRequestOperation.m */, - F8129C561591090B009BFE23 /* AFJSONUtilities.h */, - F8129C571591090B009BFE23 /* AFJSONUtilities.m */, F8129C581591090B009BFE23 /* AFNetworkActivityIndicatorManager.h */, F8129C591591090B009BFE23 /* AFNetworkActivityIndicatorManager.m */, F8129C5A1591090B009BFE23 /* AFNetworking.h */, @@ -245,7 +240,6 @@ F8129C641591090B009BFE23 /* AFHTTPRequestOperation.m in Sources */, F8129C651591090B009BFE23 /* AFImageRequestOperation.m in Sources */, F8129C661591090B009BFE23 /* AFJSONRequestOperation.m in Sources */, - F8129C671591090B009BFE23 /* AFJSONUtilities.m in Sources */, F8129C681591090B009BFE23 /* AFNetworkActivityIndicatorManager.m in Sources */, F8129C691591090B009BFE23 /* AFPropertyListRequestOperation.m in Sources */, F8129C6A1591090B009BFE23 /* AFURLConnectionOperation.m in Sources */, diff --git a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj index 7abdbab..da11cae 100644 --- a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj @@ -27,7 +27,6 @@ F8FA94B2150EFEC100ED4EAD /* AFHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA949F150EFEC100ED4EAD /* AFHTTPRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8FA94B3150EFEC100ED4EAD /* AFImageRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A1150EFEC100ED4EAD /* AFImageRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8FA94B4150EFEC100ED4EAD /* AFJSONRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A3150EFEC100ED4EAD /* AFJSONRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94B5150EFEC100ED4EAD /* AFJSONUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A5150EFEC100ED4EAD /* AFJSONUtilities.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8FA94B6150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A7150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8FA94B7150EFEC100ED4EAD /* AFPropertyListRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94AA150EFEC100ED4EAD /* AFPropertyListRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8FA94B8150EFEC100ED4EAD /* AFURLConnectionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94AC150EFEC100ED4EAD /* AFURLConnectionOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; @@ -71,8 +70,6 @@ F8FA94A1150EFEC100ED4EAD /* AFImageRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFImageRequestOperation.m; sourceTree = ""; }; F8FA94A2150EFEC100ED4EAD /* AFJSONRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFJSONRequestOperation.h; sourceTree = ""; }; F8FA94A3150EFEC100ED4EAD /* AFJSONRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFJSONRequestOperation.m; sourceTree = ""; }; - F8FA94A4150EFEC100ED4EAD /* AFJSONUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFJSONUtilities.h; sourceTree = ""; }; - F8FA94A5150EFEC100ED4EAD /* AFJSONUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFJSONUtilities.m; sourceTree = ""; }; F8FA94A6150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFNetworkActivityIndicatorManager.h; sourceTree = ""; }; F8FA94A7150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AFNetworkActivityIndicatorManager.m; sourceTree = ""; }; F8FA94A8150EFEC100ED4EAD /* AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AFNetworking.h; sourceTree = ""; }; @@ -249,8 +246,6 @@ F8FA94B0150EFEC100ED4EAD /* UIImageView+AFNetworking.m */, F8FA94A6150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.h */, F8FA94A7150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m */, - F8FA94A4150EFEC100ED4EAD /* AFJSONUtilities.h */, - F8FA94A5150EFEC100ED4EAD /* AFJSONUtilities.m */, ); name = AFNetworking; path = ../AFNetworking; @@ -332,7 +327,6 @@ F8FA94B2150EFEC100ED4EAD /* AFHTTPRequestOperation.m in Sources */, F8FA94B3150EFEC100ED4EAD /* AFImageRequestOperation.m in Sources */, F8FA94B4150EFEC100ED4EAD /* AFJSONRequestOperation.m in Sources */, - F8FA94B5150EFEC100ED4EAD /* AFJSONUtilities.m in Sources */, F8FA94B6150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m in Sources */, F8FA94B7150EFEC100ED4EAD /* AFPropertyListRequestOperation.m in Sources */, F8FA94B8150EFEC100ED4EAD /* AFURLConnectionOperation.m in Sources */, From de76f997fbbfb03293c15e8077f63b1ee63433cf Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 08:52:01 -0700 Subject: [PATCH 02/81] Setting deployment target to iOS 5.0 --- Example/AFNetworking iOS Example.xcodeproj/project.pbxproj | 4 ++-- Example/iOS-Info.plist | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj index da11cae..39e7fc7 100644 --- a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj @@ -386,7 +386,7 @@ GCC_WARN_SIGN_COMPARE = YES; GCC_WARN_UNUSED_PARAMETER = NO; INFOPLIST_FILE = "iOS-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 4.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -405,7 +405,7 @@ GCC_WARN_SIGN_COMPARE = YES; GCC_WARN_UNUSED_PARAMETER = NO; INFOPLIST_FILE = "iOS-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 4.0; + IPHONEOS_DEPLOYMENT_TARGET = 5.0; PRODUCT_NAME = "$(TARGET_NAME)"; VALIDATE_PRODUCT = YES; WRAPPER_EXTENSION = app; diff --git a/Example/iOS-Info.plist b/Example/iOS-Info.plist index 3ce184f..7e523a4 100644 --- a/Example/iOS-Info.plist +++ b/Example/iOS-Info.plist @@ -41,14 +41,14 @@ CFBundleSignature ???? CFBundleVersion - 0.1.0 + 1.0.0 LSRequiresIPhoneOS + UIPrerenderedIcon + UISupportedInterfaceOrientations UIInterfaceOrientationPortrait - UIPrerenderedIcon - From b420c181eda78296fa9955b3d09d1aac1c21340f Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 08:53:15 -0700 Subject: [PATCH 03/81] Adding compiler directive to ignore User +sharedProfileImageRequestOperationQueue in iOS --- Example/Classes/Models/User.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Example/Classes/Models/User.m b/Example/Classes/Models/User.m index 6f54c7f..18da822 100644 --- a/Example/Classes/Models/User.m +++ b/Example/Classes/Models/User.m @@ -25,9 +25,11 @@ NSString * const kUserProfileImageDidLoadNotification = @"com.alamofire.user.profile-image.loaded"; +#if __MAC_OS_X_VERSION_MIN_REQUIRED @interface User () + (NSOperationQueue *)sharedProfileImageRequestOperationQueue; @end +#endif @implementation User { @private From f1b3101a630d68aa4a15237a7c912d33051b9ea1 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 09:14:52 -0700 Subject: [PATCH 04/81] First pass at converting to ARC --- AFNetworking/AFHTTPClient.h | 4 +- AFNetworking/AFHTTPClient.m | 78 +++++-------- AFNetworking/AFHTTPRequestOperation.h | 2 +- AFNetworking/AFHTTPRequestOperation.m | 39 +++---- AFNetworking/AFImageRequestOperation.h | 2 +- AFNetworking/AFImageRequestOperation.m | 28 ++--- AFNetworking/AFJSONRequestOperation.h | 2 +- AFNetworking/AFJSONRequestOperation.m | 30 +++-- .../AFNetworkActivityIndicatorManager.m | 4 +- AFNetworking/AFPropertyListRequestOperation.h | 2 +- AFNetworking/AFPropertyListRequestOperation.m | 30 +++-- AFNetworking/AFURLConnectionOperation.h | 14 +-- AFNetworking/AFURLConnectionOperation.m | 52 +++------ AFNetworking/AFXMLRequestOperation.h | 2 +- AFNetworking/AFXMLRequestOperation.m | 36 +++--- AFNetworking/UIImageView+AFNetworking.m | 2 +- .../project.pbxproj | 108 +++++++++--------- .../project.pbxproj | 18 +-- Example/AppDelegate.h | 2 +- Example/Classes/Models/Tweet.h | 6 +- Example/Classes/Models/Tweet.m | 8 +- Example/Classes/Models/User.h | 2 +- 22 files changed, 197 insertions(+), 274 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 6d11918..249eef9 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -134,7 +134,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete /** The url used as the base for paths specified in methods such as `getPath:parameteres:success:failure` */ -@property (readonly, nonatomic, retain) NSURL *baseURL; +@property (readonly, nonatomic) NSURL *baseURL; /** The string encoding used in constructing url requests. This is `NSUTF8StringEncoding` by default. @@ -151,7 +151,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete /** The operation queue which manages operations enqueued by the HTTP client. */ -@property (readonly, nonatomic, retain) NSOperationQueue *operationQueue; +@property (readonly, nonatomic) NSOperationQueue *operationQueue; /** The reachability status from the device to the current `baseURL` of the `AFHTTPClient`. diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index fa03444..5040059 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -90,25 +90,21 @@ static NSString * AFBase64EncodedStringFromString(NSString *string) { output[idx + 3] = (i + 2) < length ? kAFBase64EncodingTable[(value >> 0) & 0x3F] : '='; } - return [[[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding] autorelease]; + return [[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding]; } NSString * AFURLEncodedStringFromStringWithEncoding(NSString *string, NSStringEncoding encoding) { static NSString * const kAFLegalCharactersToBeEscaped = @"?!@#$^&%*+=,:;'\"`<>()[]{}/\\|~ "; - return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)) autorelease]; + return (__bridge_transfer NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (__bridge CFStringRef)string, NULL, (__bridge CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)); } #pragma mark - -@interface AFQueryStringComponent : NSObject { -@private - NSString *_key; - NSString *_value; -} +@interface AFQueryStringComponent : NSObject -@property (readwrite, nonatomic, retain) id key; -@property (readwrite, nonatomic, retain) id value; +@property (readwrite, nonatomic) id key; +@property (readwrite, nonatomic) id value; - (id)initWithKey:(id)key value:(id)value; - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding; @@ -125,18 +121,12 @@ NSString * AFURLEncodedStringFromStringWithEncoding(NSString *string, NSStringEn return nil; } - self.key = key; - self.value = value; + _key = key; + _value = value; return self; } -- (void)dealloc { - [_key release]; - [_value release]; - [super dealloc]; -} - - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding { return [NSString stringWithFormat:@"%@=%@", self.key, AFURLEncodedStringFromStringWithEncoding([self.value description], stringEncoding)]; } @@ -166,7 +156,7 @@ NSArray * AFQueryStringComponentsFromKeyAndValue(NSString *key, id value) { } else if([value isKindOfClass:[NSArray class]]) { [mutableQueryStringComponents addObjectsFromArray:AFQueryStringComponentsFromKeyAndArrayValue(key, value)]; } else { - [mutableQueryStringComponents addObject:[[[AFQueryStringComponent alloc] initWithKey:key value:value] autorelease]]; + [mutableQueryStringComponents addObject:[[AFQueryStringComponent alloc] initWithKey:key value:value]]; } return mutableQueryStringComponents; @@ -197,7 +187,7 @@ static NSString * AFJSONStringFromParameters(NSDictionary *parameters) { NSData *JSONData = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:&error];; if (!error) { - return [[[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding] autorelease]; + return [[NSString alloc] initWithData:JSONData encoding:NSUTF8StringEncoding]; } else { return nil; } @@ -209,17 +199,17 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { NSData *propertyListData = [NSPropertyListSerialization dataWithPropertyList:parameters format:NSPropertyListXMLFormat_v1_0 options:0 error:&error]; if (!error) { - propertyListString = [[[NSString alloc] initWithData:propertyListData encoding:NSUTF8StringEncoding] autorelease]; + propertyListString = [[NSString alloc] initWithData:propertyListData encoding:NSUTF8StringEncoding] ; } return propertyListString; } @interface AFHTTPClient () -@property (readwrite, nonatomic, retain) NSURL *baseURL; -@property (readwrite, nonatomic, retain) NSMutableArray *registeredHTTPOperationClassNames; -@property (readwrite, nonatomic, retain) NSMutableDictionary *defaultHeaders; -@property (readwrite, nonatomic, retain) NSOperationQueue *operationQueue; +@property (readwrite, nonatomic) NSURL *baseURL; +@property (readwrite, nonatomic) NSMutableArray *registeredHTTPOperationClassNames; +@property (readwrite, nonatomic) NSMutableDictionary *defaultHeaders; +@property (readwrite, nonatomic) NSOperationQueue *operationQueue; #ifdef _SYSTEMCONFIGURATION_H @property (readwrite, nonatomic, assign) AFNetworkReachabilityRef networkReachability; @property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus; @@ -246,7 +236,7 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { #endif + (AFHTTPClient *)clientWithBaseURL:(NSURL *)url { - return [[[self alloc] initWithBaseURL:url] autorelease]; + return [[self alloc] initWithBaseURL:url]; } - (id)initWithBaseURL:(NSURL *)url { @@ -283,7 +273,7 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { [self startMonitoringNetworkReachability]; #endif - self.operationQueue = [[[NSOperationQueue alloc] init] autorelease]; + self.operationQueue = [[NSOperationQueue alloc] init]; [self.operationQueue setMaxConcurrentOperationCount:kAFHTTPClientDefaultMaxConcurrentOperationCount]; return self; @@ -292,15 +282,9 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { - (void)dealloc { #ifdef _SYSTEMCONFIGURATION_H [self stopMonitoringNetworkReachability]; - [_networkReachabilityStatusBlock release]; #endif - [_baseURL release]; - [_registeredHTTPOperationClassNames release]; - [_defaultHeaders release]; - [_operationQueue release]; - [super dealloc]; } - (NSString *)description { @@ -340,7 +324,7 @@ static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetwork static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) { AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags); - AFNetworkReachabilityStatusBlock block = (AFNetworkReachabilityStatusBlock)info; + AFNetworkReachabilityStatusBlock block = (__bridge AFNetworkReachabilityStatusBlock)info; if (block) { block(status); } @@ -349,11 +333,10 @@ static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused targ } static const void * AFNetworkReachabilityRetainCallback(const void *info) { - return [(AFNetworkReachabilityStatusBlock)info copy]; + return (__bridge_retained const void *)([(__bridge AFNetworkReachabilityStatusBlock)info copy]); } static void AFNetworkReachabilityReleaseCallback(const void *info) { - [(AFNetworkReachabilityStatusBlock)info release]; } - (void)startMonitoringNetworkReachability { @@ -372,7 +355,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { } }; - SCNetworkReachabilityContext context = {0, callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL}; + SCNetworkReachabilityContext context = {0, (__bridge void *)callback, AFNetworkReachabilityRetainCallback, AFNetworkReachabilityReleaseCallback, NULL}; SCNetworkReachabilitySetCallback(self.networkReachability, AFNetworkReachabilityCallback, &context); SCNetworkReachabilityScheduleWithRunLoop(self.networkReachability, CFRunLoopGetMain(), (CFStringRef)NSRunLoopCommonModes); @@ -449,7 +432,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { parameters:(NSDictionary *)parameters { NSURL *url = [NSURL URLWithString:path relativeToURL:self.baseURL]; - NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease]; + NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:method]; [request setAllHTTPHeaderFields:self.defaultHeaders]; @@ -462,7 +445,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:[path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding)]]; [request setURL:url]; } else { - NSString *charset = (NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); + NSString *charset = (__bridge NSString *)CFStringConvertEncodingToIANACharSetName(CFStringConvertNSStringEncodingToEncoding(self.stringEncoding)); switch (self.parameterEncoding) { case AFFormURLParameterEncoding:; [request setValue:[NSString stringWithFormat:@"application/x-www-form-urlencoded; charset=%@", charset] forHTTPHeaderField:@"Content-Type"]; @@ -489,7 +472,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { constructingBodyWithBlock:(void (^)(id formData))block { NSMutableURLRequest *request = [self requestWithMethod:method path:path parameters:nil]; - __block AFMultipartFormData *formData = [[[AFMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding] autorelease]; + __block AFMultipartFormData *formData = [[AFMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding]; if (parameters) { for (AFQueryStringComponent *component in AFQueryStringComponentsFromKeyAndValue(nil, parameters)) { @@ -523,12 +506,12 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { while (!operation && (className = [enumerator nextObject])) { Class op_class = NSClassFromString(className); if (op_class && [op_class canProcessRequest:urlRequest]) { - operation = [[(AFHTTPRequestOperation *)[op_class alloc] initWithRequest:urlRequest] autorelease]; + operation = [(AFHTTPRequestOperation *)[op_class alloc] initWithRequest:urlRequest]; } } if (!operation) { - operation = [[[AFHTTPRequestOperation alloc] initWithRequest:urlRequest] autorelease]; + operation = [[AFHTTPRequestOperation alloc] initWithRequest:urlRequest]; } [operation setCompletionBlockWithSuccess:success failure:failure]; @@ -584,7 +567,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { NSPredicate *finishedOperationPredicate = [NSPredicate predicateWithFormat:@"isFinished == YES"]; for (AFHTTPRequestOperation *operation in operations) { - AFCompletionBlock originalCompletionBlock = [[operation.completionBlock copy] autorelease]; + AFCompletionBlock originalCompletionBlock = [operation.completionBlock copy]; operation.completionBlock = ^{ dispatch_queue_t queue = operation.successCallbackQueue ? operation.successCallbackQueue : dispatch_get_main_queue(); dispatch_group_async(dispatchGroup, queue, ^{ @@ -698,9 +681,9 @@ static inline NSString * AFMultipartFormFinalBoundary() { } @interface AFMultipartFormData () -@property (readwrite, nonatomic, retain) NSMutableURLRequest *request; +@property (readwrite, nonatomic) NSMutableURLRequest *request; @property (readwrite, nonatomic, assign) NSStringEncoding stringEncoding; -@property (readwrite, nonatomic, retain) NSOutputStream *outputStream; +@property (readwrite, nonatomic) NSOutputStream *outputStream; @property (readwrite, nonatomic, copy) NSString *temporaryFilePath; @end @@ -732,16 +715,11 @@ static inline NSString * AFMultipartFormFinalBoundary() { } - (void)dealloc { - [_request release]; if (_outputStream) { [_outputStream close]; - [_outputStream release]; - _outputStream = nil; } - [_temporaryFilePath release]; - [super dealloc]; } - (NSMutableURLRequest *)requestByFinalizingMultipartFormData { @@ -816,7 +794,7 @@ static inline NSString * AFMultipartFormFinalBoundary() { [userInfo setValue:fileURL forKey:NSURLErrorFailingURLErrorKey]; [userInfo setValue:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey]; if (error != NULL) { - *error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease]; + *error = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo]; } return NO; diff --git a/AFNetworking/AFHTTPRequestOperation.h b/AFNetworking/AFHTTPRequestOperation.h index 9cab0e5..52de1f7 100644 --- a/AFNetworking/AFHTTPRequestOperation.h +++ b/AFNetworking/AFHTTPRequestOperation.h @@ -42,7 +42,7 @@ extern NSString * AFCreateIncompleteDownloadDirectoryPath(void); /** The last HTTP response received by the operation's connection. */ -@property (readonly, nonatomic, retain) NSHTTPURLResponse *response; +@property (readonly, nonatomic, strong) NSHTTPURLResponse *response; /** Set a target file for the response, will stream directly into this destination. diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index bc9b2b7..fea0235 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -29,7 +29,7 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) { static NSCharacterSet *_skippedCharacterSet = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - _skippedCharacterSet = [[NSCharacterSet characterSetWithCharactersInString:@" ,"] retain]; + _skippedCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@" ,"]; }); if (!string) { @@ -96,14 +96,13 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ NSString *tempDirectory = NSTemporaryDirectory(); - incompleteDownloadPath = [[tempDirectory stringByAppendingPathComponent:kAFNetworkingIncompleteDownloadDirectoryName] retain]; + incompleteDownloadPath = [tempDirectory stringByAppendingPathComponent:kAFNetworkingIncompleteDownloadDirectoryName]; NSError *error = nil; NSFileManager *fileMan = [[NSFileManager alloc] init]; if(![fileMan createDirectoryAtPath:incompleteDownloadPath withIntermediateDirectories:YES attributes:nil error:&error]) { NSLog(@"Failed to create incomplete downloads directory at %@", incompleteDownloadPath); } - [fileMan release]; }); return incompleteDownloadPath; @@ -112,9 +111,9 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { #pragma mark - @interface AFHTTPRequestOperation () -@property (readwrite, nonatomic, retain) NSURLRequest *request; -@property (readwrite, nonatomic, retain) NSHTTPURLResponse *response; -@property (readwrite, nonatomic, retain) NSError *HTTPError; +@property (readwrite, nonatomic, strong) NSURLRequest *request; +@property (readwrite, nonatomic, strong) NSHTTPURLResponse *response; +@property (readwrite, nonatomic, strong) NSError *HTTPError; @property (assign) long long totalContentLength; @property (assign) long long offsetContentLength; @end @@ -130,7 +129,6 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { @dynamic response; - (void)dealloc { - [_HTTPError release]; if (_successCallbackQueue) { dispatch_release(_successCallbackQueue); @@ -142,7 +140,6 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { _failureCallbackQueue = NULL; } - [super dealloc]; } - (NSError *)error { @@ -152,13 +149,13 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code in (%@), got %d", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), [self.response statusCode]] forKey:NSLocalizedDescriptionKey]; [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; - self.HTTPError = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo] autorelease]; + self.HTTPError = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo]; } else if ([self.responseData length] > 0 && ![self hasAcceptableContentType]) { // Don't invalidate content type if there is no content NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected content type %@, got %@", nil), [[self class] acceptableContentTypes], [self.response MIMEType]] forKey:NSLocalizedDescriptionKey]; [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; - self.HTTPError = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo] autorelease]; + self.HTTPError = [[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo]; } } @@ -177,7 +174,7 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { offset = [[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length]; } - NSMutableURLRequest *mutableURLRequest = [[self.request mutableCopy] autorelease]; + NSMutableURLRequest *mutableURLRequest = [self.request mutableCopy]; if ([[self.response allHeaderFields] valueForKey:@"ETag"]) { [mutableURLRequest setValue:[[self.response allHeaderFields] valueForKey:@"ETag"] forHTTPHeaderField:@"If-Range"]; } @@ -226,21 +223,22 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { + __weak AFHTTPRequestOperation *weakSelf = self; self.completionBlock = ^ { - if ([self isCancelled]) { + if ([weakSelf isCancelled]) { return; } - if (self.error) { + if (weakSelf.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(self, self.error); + dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ + failure(weakSelf, weakSelf.error); }); } } else { if (success) { - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(self, self.responseData); + dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ + success(weakSelf, weakSelf.responseData); }); } } @@ -249,8 +247,7 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { - (void)setResponseFilePath:(NSString *)responseFilePath { if ([self isReady] && responseFilePath != _responseFilePath) { - [_responseFilePath release]; - _responseFilePath = [responseFilePath retain]; + _responseFilePath = responseFilePath; if (responseFilePath) { self.outputStream = [NSOutputStream outputStreamToFileAtPath:responseFilePath append:NO]; @@ -271,7 +268,7 @@ static id AFStaticClassValueImplementation(id self, SEL _cmd) { } + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes { - NSMutableIndexSet *mutableStatusCodes = [[[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]] autorelease]; + NSMutableIndexSet *mutableStatusCodes = [[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]]; [mutableStatusCodes addIndexes:statusCodes]; SEL selector = @selector(acceptableStatusCodes); AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation); @@ -283,7 +280,7 @@ static id AFStaticClassValueImplementation(id self, SEL _cmd) { } + (void)addAcceptableContentTypes:(NSSet *)contentTypes { - NSMutableSet *mutableContentTypes = [[[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES] autorelease]; + NSMutableSet *mutableContentTypes = [[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES]; [mutableContentTypes unionSet:contentTypes]; SEL selector = @selector(acceptableContentTypes); AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation); diff --git a/AFNetworking/AFImageRequestOperation.h b/AFNetworking/AFImageRequestOperation.h index f6de586..c9c5f22 100644 --- a/AFNetworking/AFImageRequestOperation.h +++ b/AFNetworking/AFImageRequestOperation.h @@ -55,7 +55,7 @@ An image constructed from the response data. If an error occurs during the request, `nil` will be returned, and the `error` property will be set to the error. */ #if __IPHONE_OS_VERSION_MIN_REQUIRED -@property (readonly, nonatomic, retain) UIImage *responseImage; +@property (readonly, nonatomic) UIImage *responseImage; #elif __MAC_OS_X_VERSION_MIN_REQUIRED @property (readonly, nonatomic, retain) NSImage *responseImage; #endif diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index beeae69..3b13463 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -33,7 +33,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { @interface AFImageRequestOperation () #if __IPHONE_OS_VERSION_MIN_REQUIRED -@property (readwrite, nonatomic, retain) UIImage *responseImage; +@property (readwrite, nonatomic) UIImage *responseImage; #elif __MAC_OS_X_VERSION_MIN_REQUIRED @property (readwrite, nonatomic, retain) NSImage *responseImage; #endif @@ -74,7 +74,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image))success failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure { - AFImageRequestOperation *requestOperation = [[[AFImageRequestOperation alloc] initWithRequest:urlRequest] autorelease]; + AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if (success) { UIImage *image = responseObject; @@ -105,7 +105,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSImage *image))success failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error))failure { - AFImageRequestOperation *requestOperation = [[[AFImageRequestOperation alloc] initWithRequest:urlRequest] autorelease]; + AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if (success) { NSImage *image = responseObject; @@ -144,10 +144,6 @@ static dispatch_queue_t image_request_operation_processing_queue() { return self; } -- (void)dealloc { - [_responseImage release]; - [super dealloc]; -} #if __IPHONE_OS_VERSION_MIN_REQUIRED - (UIImage *)responseImage { @@ -174,9 +170,8 @@ static dispatch_queue_t image_request_operation_processing_queue() { if (!_responseImage && [self.responseData length] > 0 && [self isFinished]) { // Ensure that the image is set to it's correct pixel width and height NSBitmapImageRep *bitimage = [[NSBitmapImageRep alloc] initWithData:self.responseData]; - self.responseImage = [[[NSImage alloc] initWithSize:NSMakeSize([bitimage pixelsWide], [bitimage pixelsHigh])] autorelease]; + self.responseImage = [[NSImage alloc] initWithSize:NSMakeSize([bitimage pixelsWide], [bitimage pixelsHigh])]; [self.responseImage addRepresentation:bitimage]; - [bitimage release]; } return _responseImage; @@ -202,16 +197,17 @@ static dispatch_queue_t image_request_operation_processing_queue() { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { + __weak AFImageRequestOperation *weakSelf = self; self.completionBlock = ^ { - if ([self isCancelled]) { + if ([weakSelf isCancelled]) { return; } dispatch_async(image_request_operation_processing_queue(), ^(void) { - if (self.error) { + if (weakSelf.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(self, self.error); + dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ + failure(weakSelf, weakSelf.error); }); } } else { @@ -222,10 +218,10 @@ static dispatch_queue_t image_request_operation_processing_queue() { NSImage *image = nil; #endif - image = self.responseImage; + image = weakSelf.responseImage; - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(self, image); + dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ + success(weakSelf, image); }); } } diff --git a/AFNetworking/AFJSONRequestOperation.h b/AFNetworking/AFJSONRequestOperation.h index a1191f9..bca959c 100644 --- a/AFNetworking/AFJSONRequestOperation.h +++ b/AFNetworking/AFJSONRequestOperation.h @@ -44,7 +44,7 @@ /** A JSON object constructed from the response data. If an error occurs while parsing, `nil` will be returned, and the `error` property will be set to the error. */ -@property (readonly, nonatomic, retain) id responseJSON; +@property (readonly, nonatomic) id responseJSON; ///---------------------------------- /// @name Creating Request Operations diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index 133293b..e6968d9 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -32,8 +32,8 @@ static dispatch_queue_t json_request_operation_processing_queue() { } @interface AFJSONRequestOperation () -@property (readwrite, nonatomic, retain) id responseJSON; -@property (readwrite, nonatomic, retain) NSError *JSONError; +@property (readwrite, nonatomic) id responseJSON; +@property (readwrite, nonatomic) NSError *JSONError; @end @implementation AFJSONRequestOperation @@ -44,7 +44,7 @@ static dispatch_queue_t json_request_operation_processing_queue() { success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id JSON))success failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON))failure { - AFJSONRequestOperation *requestOperation = [[[self alloc] initWithRequest:urlRequest] autorelease]; + AFJSONRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if (success) { success(operation.request, operation.response, responseObject); @@ -58,11 +58,6 @@ static dispatch_queue_t json_request_operation_processing_queue() { return requestOperation; } -- (void)dealloc { - [_responseJSON release]; - [_JSONError release]; - [super dealloc]; -} - (id)responseJSON { if (!_responseJSON && [self.responseData length] > 0 && [self isFinished] && !self.JSONError) { @@ -101,31 +96,32 @@ static dispatch_queue_t json_request_operation_processing_queue() { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { + __weak AFJSONRequestOperation *weakSelf = self; self.completionBlock = ^ { - if ([self isCancelled]) { + if ([weakSelf isCancelled]) { return; } - if (self.error) { + if (weakSelf.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(self, self.error); + dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ + failure(weakSelf, weakSelf.error); }); } } else { dispatch_async(json_request_operation_processing_queue(), ^{ - id JSON = self.responseJSON; + id JSON = weakSelf.responseJSON; if (self.JSONError) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(self, self.error); + dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ + failure(weakSelf, weakSelf.error); }); } } else { if (success) { - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(self, JSON); + dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ + success(weakSelf, JSON); }); } } diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index b141323..dda196c 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -29,7 +29,7 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; @interface AFNetworkActivityIndicatorManager () @property (readwrite, atomic, assign) NSInteger activityCount; -@property (readwrite, nonatomic, retain) NSTimer *activityIndicatorVisibilityTimer; +@property (readwrite, nonatomic) NSTimer *activityIndicatorVisibilityTimer; @property (readonly, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible; - (void)updateNetworkActivityIndicatorVisibility; @@ -67,9 +67,7 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.25; [[NSNotificationCenter defaultCenter] removeObserver:self]; [_activityIndicatorVisibilityTimer invalidate]; - [_activityIndicatorVisibilityTimer release]; _activityIndicatorVisibilityTimer = nil; - [super dealloc]; } - (void)updateNetworkActivityIndicatorVisibilityDelayed { diff --git a/AFNetworking/AFPropertyListRequestOperation.h b/AFNetworking/AFPropertyListRequestOperation.h index aa6e471..c509274 100644 --- a/AFNetworking/AFPropertyListRequestOperation.h +++ b/AFNetworking/AFPropertyListRequestOperation.h @@ -41,7 +41,7 @@ /** An object deserialized from a plist constructed using the response data. */ -@property (readonly, nonatomic, retain) id responsePropertyList; +@property (readonly, nonatomic) id responsePropertyList; ///-------------------------------------- /// @name Managing Property List Behavior diff --git a/AFNetworking/AFPropertyListRequestOperation.m b/AFNetworking/AFPropertyListRequestOperation.m index ecca1af..2cf0d9d 100644 --- a/AFNetworking/AFPropertyListRequestOperation.m +++ b/AFNetworking/AFPropertyListRequestOperation.m @@ -32,9 +32,9 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { } @interface AFPropertyListRequestOperation () -@property (readwrite, nonatomic, retain) id responsePropertyList; +@property (readwrite, nonatomic) id responsePropertyList; @property (readwrite, nonatomic, assign) NSPropertyListFormat propertyListFormat; -@property (readwrite, nonatomic, retain) NSError *propertyListError; +@property (readwrite, nonatomic) NSError *propertyListError; @end @implementation AFPropertyListRequestOperation @@ -47,7 +47,7 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, id propertyList))success failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id propertyList))failure { - AFPropertyListRequestOperation *requestOperation = [[[self alloc] initWithRequest:request] autorelease]; + AFPropertyListRequestOperation *requestOperation = [[self alloc] initWithRequest:request]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if (success) { success(operation.request, operation.response, responseObject); @@ -72,11 +72,6 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { return self; } -- (void)dealloc { - [_responsePropertyList release]; - [_propertyListError release]; - [super dealloc]; -} - (id)responsePropertyList { if (!_responsePropertyList && [self.responseData length] > 0 && [self isFinished]) { @@ -111,31 +106,32 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { + __weak AFPropertyListRequestOperation *weakSelf = self; self.completionBlock = ^ { - if ([self isCancelled]) { + if ([weakSelf isCancelled]) { return; } - if (self.error) { + if (weakSelf.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(self, self.error); + dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ + failure(weakSelf, weakSelf.error); }); } } else { dispatch_async(property_list_request_operation_processing_queue(), ^(void) { - id propertyList = self.responsePropertyList; + id propertyList = weakSelf.responsePropertyList; if (self.propertyListError) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(self, self.error); + dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ + failure(weakSelf, weakSelf.error); }); } } else { if (success) { - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(self, propertyList); + dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ + success(weakSelf, propertyList); }); } } diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 0da353a..5879526 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -84,7 +84,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; /** The run loop modes in which the operation will run on the network thread. By default, this is a single-member set containing `NSRunLoopCommonModes`. */ -@property (nonatomic, retain) NSSet *runLoopModes; +@property (nonatomic) NSSet *runLoopModes; ///----------------------------------------- /// @name Getting URL Connection Information @@ -93,17 +93,17 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; /** The request used by the operation's connection. */ -@property (readonly, nonatomic, retain) NSURLRequest *request; +@property (readonly, nonatomic, strong) NSURLRequest *request; /** The last response received by the operation's connection. */ -@property (readonly, nonatomic, retain) NSURLResponse *response; +@property (readonly, nonatomic, strong) NSURLResponse *response; /** The error, if any, that occured in the lifecycle of the request. */ -@property (readonly, nonatomic, retain) NSError *error; +@property (readonly, nonatomic, strong) NSError *error; ///---------------------------- /// @name Getting Response Data @@ -112,7 +112,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; /** The data received during the request. */ -@property (readonly, nonatomic, retain) NSData *responseData; +@property (readonly, nonatomic, strong) NSData *responseData; /** The string representation of the response data. @@ -130,14 +130,14 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; @discussion This property acts as a proxy to the `HTTPBodyStream` property of `request`. */ -@property (nonatomic, retain) NSInputStream *inputStream; +@property (nonatomic) NSInputStream *inputStream; /** The output stream that is used to write data received until the request is finished. @discussion By default, data is accumulated into a buffer that is stored into `responseData` upon completion of the request. When `outputStream` is set, the data will not be accumulated into an internal buffer, and as a result, the `responseData` property of the completed request will be `nil`. The output stream will be scheduled in the network thread runloop upon being set. */ -@property (nonatomic, retain) NSOutputStream *outputStream; +@property (nonatomic) NSOutputStream *outputStream; ///------------------------------------------------------ /// @name Initializing an AFURLConnectionOperation Object diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 9686580..936a2d2 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -103,12 +103,12 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat @interface AFURLConnectionOperation () @property (readwrite, nonatomic, assign) AFOperationState state; @property (readwrite, nonatomic, assign, getter = isCancelled) BOOL cancelled; -@property (readwrite, nonatomic, retain) NSRecursiveLock *lock; -@property (readwrite, nonatomic, retain) NSURLConnection *connection; -@property (readwrite, nonatomic, retain) NSURLRequest *request; -@property (readwrite, nonatomic, retain) NSURLResponse *response; -@property (readwrite, nonatomic, retain) NSError *error; -@property (readwrite, nonatomic, retain) NSData *responseData; +@property (readwrite, nonatomic, strong) NSRecursiveLock *lock; +@property (readwrite, nonatomic, strong) NSURLConnection *connection; +@property (readwrite, nonatomic, strong) NSURLRequest *request; +@property (readwrite, nonatomic, strong) NSURLResponse *response; +@property (readwrite, nonatomic, strong) NSError *error; +@property (readwrite, nonatomic, strong) NSData *responseData; @property (readwrite, nonatomic, copy) NSString *responseString; @property (readwrite, nonatomic, assign) long long totalBytesRead; @property (readwrite, nonatomic, assign) AFBackgroundTaskIdentifier backgroundTaskIdentifier; @@ -147,9 +147,9 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat + (void)networkRequestThreadEntryPoint:(id)__unused object { do { - NSAutoreleasePool *runLoopPool = [[NSAutoreleasePool alloc] init]; - [[NSRunLoop currentRunLoop] run]; - [runLoopPool drain]; + @autoreleasepool { + [[NSRunLoop currentRunLoop] run]; + } } while (YES); } @@ -171,7 +171,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat return nil; } - self.lock = [[[NSRecursiveLock alloc] init] autorelease]; + self.lock = [[NSRecursiveLock alloc] init]; self.lock.name = kAFNetworkingLockName; self.runLoopModes = [NSSet setWithObject:NSRunLoopCommonModes]; @@ -186,20 +186,12 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } - (void)dealloc { - [_lock release]; - [_runLoopModes release]; - [_request release]; - [_response release]; - [_error release]; - [_responseData release]; - [_responseString release]; if (_outputStream) { [_outputStream close]; - [_outputStream release]; _outputStream = nil; } @@ -210,16 +202,8 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } #endif - [_uploadProgress release]; - [_downloadProgress release]; - [_authenticationChallenge release]; - [_authenticationAgainstProtectionSpace release]; - [_cacheResponse release]; - [_redirectResponse release]; - [_connection release]; - [super dealloc]; } - (NSString *)description { @@ -231,7 +215,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat if (!block) { [super setCompletionBlock:nil]; } else { - __block id _blockSelf = self; + __unsafe_unretained id _blockSelf = self; [super setCompletionBlock:^ { block(); [_blockSelf setCompletionBlock:nil]; @@ -246,7 +230,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat - (void)setInputStream:(NSInputStream *)inputStream { [self willChangeValueForKey:@"inputStream"]; - NSMutableURLRequest *mutableRequest = [[self.request mutableCopy] autorelease]; + NSMutableURLRequest *mutableRequest = [self.request mutableCopy]; mutableRequest.HTTPBodyStream = inputStream; self.request = mutableRequest; [self didChangeValueForKey:@"inputStream"]; @@ -254,11 +238,9 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat - (void)setOutputStream:(NSOutputStream *)outputStream { [self willChangeValueForKey:@"outputStream"]; - [outputStream retain]; if (_outputStream) { [_outputStream close]; - [_outputStream release]; } _outputStream = outputStream; [self didChangeValueForKey:@"outputStream"]; @@ -344,10 +326,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat if (!_responseString && self.response && self.responseData) { NSStringEncoding textEncoding = NSUTF8StringEncoding; if (self.response.textEncodingName) { - textEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((CFStringRef)self.response.textEncodingName)); + textEncoding = CFStringConvertEncodingToNSStringEncoding(CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)self.response.textEncodingName)); } - self.responseString = [[[NSString alloc] initWithData:self.responseData encoding:textEncoding] autorelease]; + self.responseString = [[NSString alloc] initWithData:self.responseData encoding:textEncoding]; } [self.lock unlock]; @@ -416,7 +398,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat if ([self isCancelled]) { [self finish]; } else { - self.connection = [[[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO] autorelease]; + self.connection = [[NSURLConnection alloc] initWithRequest:self.request delegate:self startImmediately:NO]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; for (NSString *runLoopMode in self.runLoopModes) { @@ -496,8 +478,8 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge if ([challenge previousFailureCount] == 0) { NSURLCredential *credential = nil; - NSString *username = [(NSString *)CFURLCopyUserName((CFURLRef)[self.request URL]) autorelease]; - NSString *password = [(NSString *)CFURLCopyPassword((CFURLRef)[self.request URL]) autorelease]; + NSString *username = (__bridge_transfer NSString *)CFURLCopyUserName((__bridge CFURLRef)[self.request URL]); + NSString *password = (__bridge_transfer NSString *)CFURLCopyPassword((__bridge CFURLRef)[self.request URL]); if (username && password) { credential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone]; diff --git a/AFNetworking/AFXMLRequestOperation.h b/AFNetworking/AFXMLRequestOperation.h index 0beb677..ca16d42 100644 --- a/AFNetworking/AFXMLRequestOperation.h +++ b/AFNetworking/AFXMLRequestOperation.h @@ -48,7 +48,7 @@ /** An `NSXMLParser` object constructed from the response data. */ -@property (readonly, nonatomic, retain) NSXMLParser *responseXMLParser; +@property (readonly, nonatomic) NSXMLParser *responseXMLParser; #if __MAC_OS_X_VERSION_MIN_REQUIRED /** diff --git a/AFNetworking/AFXMLRequestOperation.m b/AFNetworking/AFXMLRequestOperation.m index f40cacb..dbc62a1 100644 --- a/AFNetworking/AFXMLRequestOperation.m +++ b/AFNetworking/AFXMLRequestOperation.m @@ -34,11 +34,11 @@ static dispatch_queue_t xml_request_operation_processing_queue() { } @interface AFXMLRequestOperation () -@property (readwrite, nonatomic, retain) NSXMLParser *responseXMLParser; +@property (readwrite, nonatomic) NSXMLParser *responseXMLParser; #if __MAC_OS_X_VERSION_MIN_REQUIRED @property (readwrite, nonatomic, retain) NSXMLDocument *responseXMLDocument; #endif -@property (readwrite, nonatomic, retain) NSError *XMLError; +@property (readwrite, nonatomic) NSError *XMLError; @end @implementation AFXMLRequestOperation @@ -52,7 +52,7 @@ static dispatch_queue_t xml_request_operation_processing_queue() { success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLParser *XMLParser))success failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLParser *XMLParser))failure { - AFXMLRequestOperation *requestOperation = [[[self alloc] initWithRequest:urlRequest] autorelease]; + AFXMLRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if (success) { success(operation.request, operation.response, responseObject); @@ -71,7 +71,7 @@ static dispatch_queue_t xml_request_operation_processing_queue() { success:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSXMLDocument *document))success failure:(void (^)(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, NSXMLDocument *document))failure { - AFXMLRequestOperation *requestOperation = [[[self alloc] initWithRequest:urlRequest] autorelease]; + AFXMLRequestOperation *requestOperation = [[self alloc] initWithRequest:urlRequest]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, __unused id responseObject) { if (success) { NSXMLDocument *XMLDocument = [(AFXMLRequestOperation *)operation responseXMLDocument]; @@ -88,21 +88,10 @@ static dispatch_queue_t xml_request_operation_processing_queue() { } #endif -- (void)dealloc { - [_responseXMLParser release]; - -#if __MAC_OS_X_VERSION_MIN_REQUIRED - [_responseXMLDocument release]; -#endif - - [_XMLError release]; - - [super dealloc]; -} - (NSXMLParser *)responseXMLParser { if (!_responseXMLParser && [self.responseData length] > 0 && [self isFinished]) { - self.responseXMLParser = [[[NSXMLParser alloc] initWithData:self.responseData] autorelease]; + self.responseXMLParser = [[NSXMLParser alloc] initWithData:self.responseData]; } return _responseXMLParser; @@ -112,7 +101,7 @@ static dispatch_queue_t xml_request_operation_processing_queue() { - (NSXMLDocument *)responseXMLDocument { if (!_responseXMLDocument && [self.responseData length] > 0 && [self isFinished]) { NSError *error = nil; - self.responseXMLDocument = [[[NSXMLDocument alloc] initWithData:self.responseData options:0 error:&error] autorelease]; + self.responseXMLDocument = [[NSXMLDocument alloc] initWithData:self.responseData options:0 error:&error]; self.XMLError = error; } @@ -149,24 +138,25 @@ static dispatch_queue_t xml_request_operation_processing_queue() { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { + __weak AFXMLRequestOperation *weakSelf = self; self.completionBlock = ^ { - if ([self isCancelled]) { + if ([weakSelf isCancelled]) { return; } dispatch_async(xml_request_operation_processing_queue(), ^(void) { - NSXMLParser *XMLParser = self.responseXMLParser; + NSXMLParser *XMLParser = weakSelf.responseXMLParser; if (self.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(self, self.error); + dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ + failure(weakSelf, weakSelf.error); }); } } else { if (success) { - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(self, XMLParser); + dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ + success(weakSelf, XMLParser); }); } } diff --git a/AFNetworking/UIImageView+AFNetworking.m b/AFNetworking/UIImageView+AFNetworking.m index ac1f708..d694c35 100644 --- a/AFNetworking/UIImageView+AFNetworking.m +++ b/AFNetworking/UIImageView+AFNetworking.m @@ -111,7 +111,7 @@ static char kAFImageRequestOperationObjectKey; } else { self.image = placeholderImage; - AFImageRequestOperation *requestOperation = [[[AFImageRequestOperation alloc] initWithRequest:urlRequest] autorelease]; + AFImageRequestOperation *requestOperation = [[AFImageRequestOperation alloc] initWithRequest:urlRequest]; [requestOperation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { if ([[urlRequest URL] isEqual:[[self.af_imageRequestOperation request] URL]]) { self.image = responseObject; diff --git a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj index e537260..e3a71f2 100644 --- a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj @@ -11,18 +11,16 @@ F8129C321591073C009BFE23 /* AFTwitterAPIClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C251591073C009BFE23 /* AFTwitterAPIClient.m */; }; F8129C341591073C009BFE23 /* Tweet.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C2B1591073C009BFE23 /* Tweet.m */; }; F8129C351591073C009BFE23 /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C2D1591073C009BFE23 /* User.m */; }; - F8129C631591090B009BFE23 /* AFHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C4F1591090B009BFE23 /* AFHTTPClient.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C641591090B009BFE23 /* AFHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C511591090B009BFE23 /* AFHTTPRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C651591090B009BFE23 /* AFImageRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C531591090B009BFE23 /* AFImageRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C661591090B009BFE23 /* AFJSONRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C551591090B009BFE23 /* AFJSONRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C681591090B009BFE23 /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C591591090B009BFE23 /* AFNetworkActivityIndicatorManager.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C691591090B009BFE23 /* AFPropertyListRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C5C1591090B009BFE23 /* AFPropertyListRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C6A1591090B009BFE23 /* AFURLConnectionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C5E1591090B009BFE23 /* AFURLConnectionOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C6B1591090B009BFE23 /* AFXMLRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C601591090B009BFE23 /* AFXMLRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8129C6C1591090B009BFE23 /* UIImageView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C621591090B009BFE23 /* UIImageView+AFNetworking.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; F8129C6F15910B15009BFE23 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C6E15910B15009BFE23 /* main.m */; }; F8129C7115910B3E009BFE23 /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F8129C7015910B3E009BFE23 /* MainMenu.xib */; }; F8129C7715910C40009BFE23 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = F8129C7515910C40009BFE23 /* AppDelegate.m */; }; + F82EB07C159A172000B10B56 /* AFHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F82EB06E159A172000B10B56 /* AFHTTPClient.m */; }; + F82EB07D159A172000B10B56 /* AFHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F82EB070159A172000B10B56 /* AFHTTPRequestOperation.m */; }; + F82EB07E159A172000B10B56 /* AFImageRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F82EB072159A172000B10B56 /* AFImageRequestOperation.m */; }; + F82EB07F159A172000B10B56 /* AFJSONRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F82EB074159A172000B10B56 /* AFJSONRequestOperation.m */; }; + F82EB080159A172000B10B56 /* AFPropertyListRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F82EB077159A172000B10B56 /* AFPropertyListRequestOperation.m */; }; + F82EB081159A172000B10B56 /* AFURLConnectionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F82EB079159A172000B10B56 /* AFURLConnectionOperation.m */; }; + F82EB082159A172000B10B56 /* AFXMLRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F82EB07B159A172000B10B56 /* AFXMLRequestOperation.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -37,29 +35,25 @@ F8129C2C1591073C009BFE23 /* User.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = User.h; sourceTree = ""; }; F8129C2D1591073C009BFE23 /* User.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = User.m; sourceTree = ""; }; F8129C311591073C009BFE23 /* AFTwitterAPIClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFTwitterAPIClient.h; path = Classes/AFTwitterAPIClient.h; sourceTree = SOURCE_ROOT; }; - F8129C4E1591090B009BFE23 /* AFHTTPClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFHTTPClient.h; path = ../AFNetworking/AFHTTPClient.h; sourceTree = ""; }; - F8129C4F1591090B009BFE23 /* AFHTTPClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFHTTPClient.m; path = ../AFNetworking/AFHTTPClient.m; sourceTree = ""; }; - F8129C501591090B009BFE23 /* AFHTTPRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFHTTPRequestOperation.h; path = ../AFNetworking/AFHTTPRequestOperation.h; sourceTree = ""; }; - F8129C511591090B009BFE23 /* AFHTTPRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFHTTPRequestOperation.m; path = ../AFNetworking/AFHTTPRequestOperation.m; sourceTree = ""; }; - F8129C521591090B009BFE23 /* AFImageRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFImageRequestOperation.h; path = ../AFNetworking/AFImageRequestOperation.h; sourceTree = ""; }; - F8129C531591090B009BFE23 /* AFImageRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFImageRequestOperation.m; path = ../AFNetworking/AFImageRequestOperation.m; sourceTree = ""; }; - F8129C541591090B009BFE23 /* AFJSONRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFJSONRequestOperation.h; path = ../AFNetworking/AFJSONRequestOperation.h; sourceTree = ""; }; - F8129C551591090B009BFE23 /* AFJSONRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFJSONRequestOperation.m; path = ../AFNetworking/AFJSONRequestOperation.m; sourceTree = ""; }; - F8129C581591090B009BFE23 /* AFNetworkActivityIndicatorManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFNetworkActivityIndicatorManager.h; path = ../AFNetworking/AFNetworkActivityIndicatorManager.h; sourceTree = ""; }; - F8129C591591090B009BFE23 /* AFNetworkActivityIndicatorManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFNetworkActivityIndicatorManager.m; path = ../AFNetworking/AFNetworkActivityIndicatorManager.m; sourceTree = ""; }; - F8129C5A1591090B009BFE23 /* AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFNetworking.h; path = ../AFNetworking/AFNetworking.h; sourceTree = ""; }; - F8129C5B1591090B009BFE23 /* AFPropertyListRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFPropertyListRequestOperation.h; path = ../AFNetworking/AFPropertyListRequestOperation.h; sourceTree = ""; }; - F8129C5C1591090B009BFE23 /* AFPropertyListRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFPropertyListRequestOperation.m; path = ../AFNetworking/AFPropertyListRequestOperation.m; sourceTree = ""; }; - F8129C5D1591090B009BFE23 /* AFURLConnectionOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFURLConnectionOperation.h; path = ../AFNetworking/AFURLConnectionOperation.h; sourceTree = ""; }; - F8129C5E1591090B009BFE23 /* AFURLConnectionOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFURLConnectionOperation.m; path = ../AFNetworking/AFURLConnectionOperation.m; sourceTree = ""; }; - F8129C5F1591090B009BFE23 /* AFXMLRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFXMLRequestOperation.h; path = ../AFNetworking/AFXMLRequestOperation.h; sourceTree = ""; }; - F8129C601591090B009BFE23 /* AFXMLRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFXMLRequestOperation.m; path = ../AFNetworking/AFXMLRequestOperation.m; sourceTree = ""; }; - F8129C611591090B009BFE23 /* UIImageView+AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = "UIImageView+AFNetworking.h"; path = "../AFNetworking/UIImageView+AFNetworking.h"; sourceTree = ""; }; - F8129C621591090B009BFE23 /* UIImageView+AFNetworking.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = "UIImageView+AFNetworking.m"; path = "../AFNetworking/UIImageView+AFNetworking.m"; sourceTree = ""; }; F8129C6E15910B15009BFE23 /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = SOURCE_ROOT; }; F8129C7015910B3E009BFE23 /* MainMenu.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = MainMenu.xib; sourceTree = SOURCE_ROOT; }; F8129C7515910C40009BFE23 /* AppDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = SOURCE_ROOT; }; F8129C7615910C40009BFE23 /* AppDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = SOURCE_ROOT; }; + F82EB06D159A172000B10B56 /* AFHTTPClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFHTTPClient.h; path = ../AFNetworking/AFHTTPClient.h; sourceTree = ""; }; + F82EB06E159A172000B10B56 /* AFHTTPClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFHTTPClient.m; path = ../AFNetworking/AFHTTPClient.m; sourceTree = ""; }; + F82EB06F159A172000B10B56 /* AFHTTPRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFHTTPRequestOperation.h; path = ../AFNetworking/AFHTTPRequestOperation.h; sourceTree = ""; }; + F82EB070159A172000B10B56 /* AFHTTPRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFHTTPRequestOperation.m; path = ../AFNetworking/AFHTTPRequestOperation.m; sourceTree = ""; }; + F82EB071159A172000B10B56 /* AFImageRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFImageRequestOperation.h; path = ../AFNetworking/AFImageRequestOperation.h; sourceTree = ""; }; + F82EB072159A172000B10B56 /* AFImageRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFImageRequestOperation.m; path = ../AFNetworking/AFImageRequestOperation.m; sourceTree = ""; }; + F82EB073159A172000B10B56 /* AFJSONRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFJSONRequestOperation.h; path = ../AFNetworking/AFJSONRequestOperation.h; sourceTree = ""; }; + F82EB074159A172000B10B56 /* AFJSONRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFJSONRequestOperation.m; path = ../AFNetworking/AFJSONRequestOperation.m; sourceTree = ""; }; + F82EB075159A172000B10B56 /* AFNetworking.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFNetworking.h; path = ../AFNetworking/AFNetworking.h; sourceTree = ""; }; + F82EB076159A172000B10B56 /* AFPropertyListRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFPropertyListRequestOperation.h; path = ../AFNetworking/AFPropertyListRequestOperation.h; sourceTree = ""; }; + F82EB077159A172000B10B56 /* AFPropertyListRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFPropertyListRequestOperation.m; path = ../AFNetworking/AFPropertyListRequestOperation.m; sourceTree = ""; }; + F82EB078159A172000B10B56 /* AFURLConnectionOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFURLConnectionOperation.h; path = ../AFNetworking/AFURLConnectionOperation.h; sourceTree = ""; }; + F82EB079159A172000B10B56 /* AFURLConnectionOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFURLConnectionOperation.m; path = ../AFNetworking/AFURLConnectionOperation.m; sourceTree = ""; }; + F82EB07A159A172000B10B56 /* AFXMLRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFXMLRequestOperation.h; path = ../AFNetworking/AFXMLRequestOperation.h; sourceTree = ""; }; + F82EB07B159A172000B10B56 /* AFXMLRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFXMLRequestOperation.m; path = ../AFNetworking/AFXMLRequestOperation.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -149,29 +143,33 @@ F8129C4C15910901009BFE23 /* Vendor */ = { isa = PBXGroup; children = ( - F8129C4E1591090B009BFE23 /* AFHTTPClient.h */, - F8129C4F1591090B009BFE23 /* AFHTTPClient.m */, - F8129C501591090B009BFE23 /* AFHTTPRequestOperation.h */, - F8129C511591090B009BFE23 /* AFHTTPRequestOperation.m */, - F8129C521591090B009BFE23 /* AFImageRequestOperation.h */, - F8129C531591090B009BFE23 /* AFImageRequestOperation.m */, - F8129C541591090B009BFE23 /* AFJSONRequestOperation.h */, - F8129C551591090B009BFE23 /* AFJSONRequestOperation.m */, - F8129C581591090B009BFE23 /* AFNetworkActivityIndicatorManager.h */, - F8129C591591090B009BFE23 /* AFNetworkActivityIndicatorManager.m */, - F8129C5A1591090B009BFE23 /* AFNetworking.h */, - F8129C5B1591090B009BFE23 /* AFPropertyListRequestOperation.h */, - F8129C5C1591090B009BFE23 /* AFPropertyListRequestOperation.m */, - F8129C5D1591090B009BFE23 /* AFURLConnectionOperation.h */, - F8129C5E1591090B009BFE23 /* AFURLConnectionOperation.m */, - F8129C5F1591090B009BFE23 /* AFXMLRequestOperation.h */, - F8129C601591090B009BFE23 /* AFXMLRequestOperation.m */, - F8129C611591090B009BFE23 /* UIImageView+AFNetworking.h */, - F8129C621591090B009BFE23 /* UIImageView+AFNetworking.m */, + F82EB083159A172500B10B56 /* AFNetworking */, ); name = Vendor; sourceTree = ""; }; + F82EB083159A172500B10B56 /* AFNetworking */ = { + isa = PBXGroup; + children = ( + F82EB06D159A172000B10B56 /* AFHTTPClient.h */, + F82EB06E159A172000B10B56 /* AFHTTPClient.m */, + F82EB06F159A172000B10B56 /* AFHTTPRequestOperation.h */, + F82EB070159A172000B10B56 /* AFHTTPRequestOperation.m */, + F82EB071159A172000B10B56 /* AFImageRequestOperation.h */, + F82EB072159A172000B10B56 /* AFImageRequestOperation.m */, + F82EB073159A172000B10B56 /* AFJSONRequestOperation.h */, + F82EB074159A172000B10B56 /* AFJSONRequestOperation.m */, + F82EB075159A172000B10B56 /* AFNetworking.h */, + F82EB076159A172000B10B56 /* AFPropertyListRequestOperation.h */, + F82EB077159A172000B10B56 /* AFPropertyListRequestOperation.m */, + F82EB078159A172000B10B56 /* AFURLConnectionOperation.h */, + F82EB079159A172000B10B56 /* AFURLConnectionOperation.m */, + F82EB07A159A172000B10B56 /* AFXMLRequestOperation.h */, + F82EB07B159A172000B10B56 /* AFXMLRequestOperation.m */, + ); + name = AFNetworking; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -236,17 +234,15 @@ F8129C341591073C009BFE23 /* Tweet.m in Sources */, F8129C351591073C009BFE23 /* User.m in Sources */, F8129C321591073C009BFE23 /* AFTwitterAPIClient.m in Sources */, - F8129C631591090B009BFE23 /* AFHTTPClient.m in Sources */, - F8129C641591090B009BFE23 /* AFHTTPRequestOperation.m in Sources */, - F8129C651591090B009BFE23 /* AFImageRequestOperation.m in Sources */, - F8129C661591090B009BFE23 /* AFJSONRequestOperation.m in Sources */, - F8129C681591090B009BFE23 /* AFNetworkActivityIndicatorManager.m in Sources */, - F8129C691591090B009BFE23 /* AFPropertyListRequestOperation.m in Sources */, - F8129C6A1591090B009BFE23 /* AFURLConnectionOperation.m in Sources */, - F8129C6B1591090B009BFE23 /* AFXMLRequestOperation.m in Sources */, - F8129C6C1591090B009BFE23 /* UIImageView+AFNetworking.m in Sources */, F8129C6F15910B15009BFE23 /* main.m in Sources */, F8129C7715910C40009BFE23 /* AppDelegate.m in Sources */, + F82EB07C159A172000B10B56 /* AFHTTPClient.m in Sources */, + F82EB07D159A172000B10B56 /* AFHTTPRequestOperation.m in Sources */, + F82EB07E159A172000B10B56 /* AFImageRequestOperation.m in Sources */, + F82EB07F159A172000B10B56 /* AFJSONRequestOperation.m in Sources */, + F82EB080159A172000B10B56 /* AFPropertyListRequestOperation.m in Sources */, + F82EB081159A172000B10B56 /* AFURLConnectionOperation.m in Sources */, + F82EB082159A172000B10B56 /* AFXMLRequestOperation.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj index 39e7fc7..987dfbf 100644 --- a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj @@ -23,15 +23,15 @@ F8FA9494150EF97E00ED4EAD /* Tweet.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA9493150EF97E00ED4EAD /* Tweet.m */; }; F8FA9497150EF98800ED4EAD /* User.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA9496150EF98800ED4EAD /* User.m */; }; F8FA949A150EF9DA00ED4EAD /* PublicTimelineViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA9499150EF9DA00ED4EAD /* PublicTimelineViewController.m */; }; - F8FA94B1150EFEC100ED4EAD /* AFHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA949D150EFEC100ED4EAD /* AFHTTPClient.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94B2150EFEC100ED4EAD /* AFHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA949F150EFEC100ED4EAD /* AFHTTPRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94B3150EFEC100ED4EAD /* AFImageRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A1150EFEC100ED4EAD /* AFImageRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94B4150EFEC100ED4EAD /* AFJSONRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A3150EFEC100ED4EAD /* AFJSONRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94B6150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A7150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94B7150EFEC100ED4EAD /* AFPropertyListRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94AA150EFEC100ED4EAD /* AFPropertyListRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94B8150EFEC100ED4EAD /* AFURLConnectionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94AC150EFEC100ED4EAD /* AFURLConnectionOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94B9150EFEC100ED4EAD /* AFXMLRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94AE150EFEC100ED4EAD /* AFXMLRequestOperation.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; - F8FA94BA150EFEC100ED4EAD /* UIImageView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94B0150EFEC100ED4EAD /* UIImageView+AFNetworking.m */; settings = {COMPILER_FLAGS = "-fno-objc-arc"; }; }; + F8FA94B1150EFEC100ED4EAD /* AFHTTPClient.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA949D150EFEC100ED4EAD /* AFHTTPClient.m */; }; + F8FA94B2150EFEC100ED4EAD /* AFHTTPRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA949F150EFEC100ED4EAD /* AFHTTPRequestOperation.m */; }; + F8FA94B3150EFEC100ED4EAD /* AFImageRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A1150EFEC100ED4EAD /* AFImageRequestOperation.m */; }; + F8FA94B4150EFEC100ED4EAD /* AFJSONRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A3150EFEC100ED4EAD /* AFJSONRequestOperation.m */; }; + F8FA94B6150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94A7150EFEC100ED4EAD /* AFNetworkActivityIndicatorManager.m */; }; + F8FA94B7150EFEC100ED4EAD /* AFPropertyListRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94AA150EFEC100ED4EAD /* AFPropertyListRequestOperation.m */; }; + F8FA94B8150EFEC100ED4EAD /* AFURLConnectionOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94AC150EFEC100ED4EAD /* AFURLConnectionOperation.m */; }; + F8FA94B9150EFEC100ED4EAD /* AFXMLRequestOperation.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94AE150EFEC100ED4EAD /* AFXMLRequestOperation.m */; }; + F8FA94BA150EFEC100ED4EAD /* UIImageView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94B0150EFEC100ED4EAD /* UIImageView+AFNetworking.m */; }; F8FA94C1150F019100ED4EAD /* TweetTableViewCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F8FA94C0150F019100ED4EAD /* TweetTableViewCell.m */; }; F8FA94D0150F094D00ED4EAD /* profile-image-placeholder.png in Resources */ = {isa = PBXBuildFile; fileRef = F8FA94CC150F094D00ED4EAD /* profile-image-placeholder.png */; }; F8FA94D1150F094D00ED4EAD /* profile-image-placeholder@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = F8FA94CD150F094D00ED4EAD /* profile-image-placeholder@2x.png */; }; diff --git a/Example/AppDelegate.h b/Example/AppDelegate.h index 0241509..bc25a4b 100644 --- a/Example/AppDelegate.h +++ b/Example/AppDelegate.h @@ -42,7 +42,7 @@ @interface AppDelegate : NSObject @property (strong) IBOutlet NSWindow *window; -@property (weak) IBOutlet NSTableView *tableView; +@property (strong) IBOutlet NSTableView *tableView; @property (strong) IBOutlet NSArrayController *tweetsArrayController; @end diff --git a/Example/Classes/Models/Tweet.h b/Example/Classes/Models/Tweet.h index a08fd3c..9954a2b 100644 --- a/Example/Classes/Models/Tweet.h +++ b/Example/Classes/Models/Tweet.h @@ -26,10 +26,10 @@ @interface Tweet : NSObject -@property (readonly) NSUInteger tweetID; -@property (readonly) NSString *text; +@property (readonly, assign) NSUInteger tweetID; +@property (readonly, strong) NSString *text; -@property (readonly) User *user; +@property (readonly, strong) User *user; - (id)initWithAttributes:(NSDictionary *)attributes; diff --git a/Example/Classes/Models/Tweet.m b/Example/Classes/Models/Tweet.m index 14fe2d0..683e25e 100644 --- a/Example/Classes/Models/Tweet.m +++ b/Example/Classes/Models/Tweet.m @@ -25,13 +25,7 @@ #import "AFTwitterAPIClient.h" -@implementation Tweet { -@private - NSUInteger _tweetID; - __strong NSString *_text; - __strong User *_user; -} - +@implementation Tweet @synthesize tweetID = _tweetID; @synthesize text = _text; @synthesize user = _user; diff --git a/Example/Classes/Models/User.h b/Example/Classes/Models/User.h index f3ea855..25419ef 100644 --- a/Example/Classes/Models/User.h +++ b/Example/Classes/Models/User.h @@ -27,7 +27,7 @@ extern NSString * const kUserProfileImageDidLoadNotification; @interface User : NSObject @property (readonly) NSUInteger userID; -@property (readonly) NSString *username; +@property (strong, readonly) NSString *username; @property (unsafe_unretained, readonly) NSURL *profileImageURL; - (id)initWithAttributes:(NSDictionary *)attributes; From 605bbf1c28200e20f08273aafe95bf0c43ac41fd Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 09:20:57 -0700 Subject: [PATCH 05/81] [Issue #387] AFHTTPClient should setHTTPShouldHandleCookies:NO by default for requestWithMethod:path:parameters --- AFNetworking/AFHTTPClient.m | 1 + 1 file changed, 1 insertion(+) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 5040059..3bf0c11 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -435,6 +435,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:method]; [request setAllHTTPHeaderFields:self.defaultHeaders]; + [request setHTTPShouldHandleCookies:NO]; if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"]) { [request setHTTPShouldUsePipelining:YES]; From ea94ea6ffa66a9db3743e348cd39807bcf0c8fe8 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 09:34:08 -0700 Subject: [PATCH 06/81] Revert 25620fe8391183adf7ed15ebdd8c15e8802e95c6 --- AFNetworking/AFHTTPRequestOperation.m | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index fea0235..7537815 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -54,11 +54,10 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) { return [NSSet setWithSet:mutableContentTypes]; } -static void AFSwizzleClassMethodWithImplementation(Class klass, SEL selector, IMP implementation) { +static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, void *block) { Method originalMethod = class_getClassMethod(klass, selector); - if (method_getImplementation(originalMethod) != implementation) { - class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); - } + IMP implementation = imp_implementationWithBlock(block); + class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); } static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { @@ -259,10 +258,6 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { #pragma mark - AFHTTPRequestOperation -static id AFStaticClassValueImplementation(id self, SEL _cmd) { - return objc_getAssociatedObject([self class], _cmd); -} - + (NSIndexSet *)acceptableStatusCodes { return [NSIndexSet indexSetWithIndexesInRange:NSMakeRange(200, 100)]; } @@ -270,9 +265,9 @@ static id AFStaticClassValueImplementation(id self, SEL _cmd) { + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes { NSMutableIndexSet *mutableStatusCodes = [[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]]; [mutableStatusCodes addIndexes:statusCodes]; - SEL selector = @selector(acceptableStatusCodes); - AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation); - objc_setAssociatedObject([self class], selector, mutableStatusCodes, OBJC_ASSOCIATION_COPY_NONATOMIC); + AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), (__bridge void *)^(id _self) { + return mutableStatusCodes; + }); } + (NSSet *)acceptableContentTypes { @@ -282,9 +277,9 @@ static id AFStaticClassValueImplementation(id self, SEL _cmd) { + (void)addAcceptableContentTypes:(NSSet *)contentTypes { NSMutableSet *mutableContentTypes = [[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES]; [mutableContentTypes unionSet:contentTypes]; - SEL selector = @selector(acceptableContentTypes); - AFSwizzleClassMethodWithImplementation([self class], selector, (IMP)AFStaticClassValueImplementation); - objc_setAssociatedObject([self class], selector, mutableContentTypes, OBJC_ASSOCIATION_COPY_NONATOMIC); + AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), (__bridge void *)^(id _self) { + return mutableContentTypes; + }); } + (BOOL)canProcessRequest:(NSURLRequest *)request { From c6ffce05b9dfe109ed9e914aeaf2cb52d5fc1d76 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 09:35:43 -0700 Subject: [PATCH 07/81] Reorganizing vendor directory --- .../project.pbxproj | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj index e3a71f2..fd5b94b 100644 --- a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj @@ -151,21 +151,21 @@ F82EB083159A172500B10B56 /* AFNetworking */ = { isa = PBXGroup; children = ( - F82EB06D159A172000B10B56 /* AFHTTPClient.h */, - F82EB06E159A172000B10B56 /* AFHTTPClient.m */, - F82EB06F159A172000B10B56 /* AFHTTPRequestOperation.h */, - F82EB070159A172000B10B56 /* AFHTTPRequestOperation.m */, - F82EB071159A172000B10B56 /* AFImageRequestOperation.h */, - F82EB072159A172000B10B56 /* AFImageRequestOperation.m */, - F82EB073159A172000B10B56 /* AFJSONRequestOperation.h */, - F82EB074159A172000B10B56 /* AFJSONRequestOperation.m */, F82EB075159A172000B10B56 /* AFNetworking.h */, - F82EB076159A172000B10B56 /* AFPropertyListRequestOperation.h */, - F82EB077159A172000B10B56 /* AFPropertyListRequestOperation.m */, F82EB078159A172000B10B56 /* AFURLConnectionOperation.h */, F82EB079159A172000B10B56 /* AFURLConnectionOperation.m */, + F82EB06F159A172000B10B56 /* AFHTTPRequestOperation.h */, + F82EB070159A172000B10B56 /* AFHTTPRequestOperation.m */, + F82EB073159A172000B10B56 /* AFJSONRequestOperation.h */, + F82EB074159A172000B10B56 /* AFJSONRequestOperation.m */, F82EB07A159A172000B10B56 /* AFXMLRequestOperation.h */, F82EB07B159A172000B10B56 /* AFXMLRequestOperation.m */, + F82EB076159A172000B10B56 /* AFPropertyListRequestOperation.h */, + F82EB077159A172000B10B56 /* AFPropertyListRequestOperation.m */, + F82EB06D159A172000B10B56 /* AFHTTPClient.h */, + F82EB06E159A172000B10B56 /* AFHTTPClient.m */, + F82EB071159A172000B10B56 /* AFImageRequestOperation.h */, + F82EB072159A172000B10B56 /* AFImageRequestOperation.m */, ); name = AFNetworking; sourceTree = ""; From 97900fcbfa8226877e87f16fc8b05b5e884ef61d Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 09:37:53 -0700 Subject: [PATCH 08/81] Setting NSURLCache memory and disk capacity to Apple default settings --- Example/AppDelegate.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Example/AppDelegate.m b/Example/AppDelegate.m index 2e27051..22ea848 100644 --- a/Example/AppDelegate.m +++ b/Example/AppDelegate.m @@ -35,7 +35,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { - NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 diskCapacity:1024 * 1024 * 5 diskPath:nil]; + NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil]; [NSURLCache setSharedURLCache:URLCache]; [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; @@ -66,7 +66,7 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions @synthesize tweetsArrayController = _tweetsArrayController; - (void)applicationDidFinishLaunching:(NSNotification *)notification { - NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:1024 * 1024 diskCapacity:1024 * 1024 * 5 diskPath:nil]; + NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil]; [NSURLCache setSharedURLCache:URLCache]; [self.window makeKeyAndOrderFront:self]; From 1afba1b6233bd216cb9e9f673f84beb47242be83 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 09:38:34 -0700 Subject: [PATCH 09/81] Sandboxing Mac Example Application --- Example/AFNetworking Example.entitlements | 12 ++++++++++++ .../project.pbxproj | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 Example/AFNetworking Example.entitlements diff --git a/Example/AFNetworking Example.entitlements b/Example/AFNetworking Example.entitlements new file mode 100644 index 0000000..7a2230d --- /dev/null +++ b/Example/AFNetworking Example.entitlements @@ -0,0 +1,12 @@ + + + + + com.apple.security.app-sandbox + + com.apple.security.network.client + + com.apple.security.network.server + + + diff --git a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj index fd5b94b..899632e 100644 --- a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj @@ -54,6 +54,7 @@ F82EB079159A172000B10B56 /* AFURLConnectionOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFURLConnectionOperation.m; path = ../AFNetworking/AFURLConnectionOperation.m; sourceTree = ""; }; F82EB07A159A172000B10B56 /* AFXMLRequestOperation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = AFXMLRequestOperation.h; path = ../AFNetworking/AFXMLRequestOperation.h; sourceTree = ""; }; F82EB07B159A172000B10B56 /* AFXMLRequestOperation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = AFXMLRequestOperation.m; path = ../AFNetworking/AFXMLRequestOperation.m; sourceTree = ""; }; + F877018B159A1CE700B45C0D /* AFNetworking Example.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.xml; path = "AFNetworking Example.entitlements"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -71,6 +72,7 @@ F8129BF01591061B009BFE23 = { isa = PBXGroup; children = ( + F877018B159A1CE700B45C0D /* AFNetworking Example.entitlements */, F8129C051591061B009BFE23 /* Classes */, F8129C4C15910901009BFE23 /* Vendor */, F8129BFE1591061B009BFE23 /* Frameworks */, @@ -299,6 +301,8 @@ F8129C1A1591061B009BFE23 /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_ENTITLEMENTS = "AFNetworking Example.entitlements"; + CODE_SIGN_IDENTITY = "Mac Developer"; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = Prefix.pch; INFOPLIST_FILE = "Mac-Info.plist"; @@ -310,6 +314,8 @@ F8129C1B1591061B009BFE23 /* Release */ = { isa = XCBuildConfiguration; buildSettings = { + CODE_SIGN_ENTITLEMENTS = "AFNetworking Example.entitlements"; + CODE_SIGN_IDENTITY = "Mac Developer"; GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = Prefix.pch; INFOPLIST_FILE = "Mac-Info.plist"; From 8bfbcb9b9f72f58fc03dfe2f58dc6532b0b6cfb4 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 09:49:09 -0700 Subject: [PATCH 10/81] Updating iOS icon --- Example/Icon.png | Bin 4828 -> 6547 bytes Example/Icon@2x.png | Bin 13047 -> 10055 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/Example/Icon.png b/Example/Icon.png index bb79b6531a75923b330733ea0d25055989edee16..9956cb16fce70efc70e200f8f7c2bfb55b6008a6 100644 GIT binary patch literal 6547 zcmV;E8Eoc>P)KLZ*U+IBfRsybQWXdwQbLP>6pAqfylh#{fb6;Z(vMMVS~$e@S=j*ftg6;Uhf59&ghTmgWD0l;*T zI709Y^p6lP1rIRMx#05C~cW=H_Aw*bJ-5DT&Z2n+x)QHX^p z00esgV8|mQcmRZ%02D^@S3L16t`O%c004NIvOKvYIYoh62rY33S640`D9%Y2D-rV&neh&#Q1i z007~1e$oCcFS8neI|hJl{-P!B1ZZ9hpmq0)X0i`JwE&>$+E?>%_LC6RbVIkUx0b+_+BaR3cnT7Zv!AJxW zizFb)h!jyGOOZ85F;a?DAXP{m@;!0_IfqH8(HlgRxt7s3}k3K`kFu>>-2Q$QMFfPW!La{h336o>X zu_CMttHv6zR;&ZNiS=X8v3CR#fknUxHUxJ0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T>Iu^Iab26HT_}McTc5L?AWfwM~~@qn?OuW;~MSDUILO%8(Y(9 zuJbAeoopiyjWOjUiH6`%+u@R-lqbzglv*Px-~CPKf=8A4o-X7gN3CA$*W^gw7GT0j z)tX9B*|teklYBX?E|AP^f9eZkn1d9%j(gI_-cFUB`!hAGoh@+}gV)=1a_EY$_TruB zTd1?Uyo2L27q9sGQl#Vncj;@_t8(aH54_t>mqk798b6rax~m$@k`PoG$*EamD`YB> z3JzfdB|nQku+9IHA0+QHH+4ODXH6pejsJvM3P>bI2B>hK3X5HNUKSV9&rz&T)z=e1uSw3cMnq5vy85la&L(rEiZQ-Yqp9t-s25zb?5FFeJ|5x zX3v_&GZ$KF_j8t!STHNntnF4_Z#bFYDjo1Nt26dB;xRpF#P7D#zV)3gOXu9`i`Q(E zn=4M|t6Ke9U8+G(o#v!-c={wx;!z1tbj)jY6S$c_`=Jk$LFFmk(CDl@*q1-E6wnX3cdU}RS7kSp(^+0;R=05 z!|=NyG3XVj)Z6m+1C)?D!!J(;Y#Pj`LU)f|4(=TFXe^Gp^sd;Mi(ef(Cp=ko=Sc(d zs+#~-H2T@-%fn#C^#xQxFxS&ycuu*v9kWUd;_%d1;nzNSS^uMVCwT!G4mPY^4ORoc P|2OID7$HlwZifF4$_=(N diff --git a/Example/Icon@2x.png b/Example/Icon@2x.png index b8d01127454d156ad64474809c3719d38a4fb85a..7fcc2264f7d4864cd2d5838d1966981fb9937b54 100644 GIT binary patch delta 7381 zcmV;`94h1YWyemC83+OZ0002L5-PDFo(g{)a!Eu%RCwCteP@_l#g+DZs&42s-IJ3> zVWg3e2tpDP2mwNXY@)yflXq=!0JFCF)>wS7m|)`%j6W}C2{yrCgRxnHvB3r#3|dSM zE3jCEgq5Yqc{=wEb@oTM)YGG$nQk$XMyQ_q%=1j&x^=5goqErEPK8TbpFX$5r=x#> zM7o!Z0O?+m1_>P`L4GReJCl1geQN^2x-FSu;D2v8zet9!EiX%MZPNXmT|l%3j$fO>OPR< zSl4H2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6y}Dsld&M_{ksmER&PdH799eVv>KK_=$go5yO*@e~Y!XRkYR& zdOcoy?Pb3IlRvzPW_+)zmC=!%stu@naU*bqiCEdOpT%7ViK2+9sU7UydsE}NsXf`~ zt>@d)n>dTG@1_Go0qpUKF5?Bae>kW;ndLw&%ZhvKwYAC2#eMoackX7#&fWEAvu$?o z*_UNB;_H8DT-W8qTd#2F&|U0lc-BU*6$K-QKx)g#A>Sp>e^)T<*o71{bmcf=p+U%Yc3dgYrENn7EQ|6Qn5&!?uXA5QZ78N{0iO?2ho*YPHD zQ52z7;(1w?byaQChvQlcwP0CRR$Q%9BqY(bAI{MC$Vl<()Qiplfx%#a>$>#&{SSX< z>3cvLTdh{y-IneySj7^DwT^u_ZY-4w;QM|SX_OY;^?e`D^RO&yTVV5t`0sU~i zzcx{8jpun8gxG|@*_)+Ddc7X5>tcV~HiN<7L+QLus#GbJROSz#|1HIBFc@IlHm>Vt zo^5&8*AK_FkiZn|kD_R#CL Date: Tue, 26 Jun 2012 09:51:21 -0700 Subject: [PATCH 11/81] Updating requirements Removing note about ARC compatibility --- README.md | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/README.md b/README.md index 9d5fb45..efc226f 100644 --- a/README.md +++ b/README.md @@ -143,20 +143,7 @@ operation.outputStream = [NSOutputStream outputStreamToMemory]; ## Requirements -AFNetworking requires either [iOS 4.0](http://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS4.html) and above, or [Mac OS 10.6](http://developer.apple.com/library/mac/#releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_6.html#//apple_ref/doc/uid/TP40008898-SW7) ([64-bit with modern Cocoa runtime](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtVersionsPlatforms.html)) and above. - -AFNetworking uses [`NSJSONSerialization`](http://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSJSONSerialization_Class/Reference/Reference.html) if it is available. If your app targets a platform where this class is not available you can include one of the following JSON libraries to your project for AFNetworking to automatically detect and use. - -* [JSONKit](https://github.com/johnezang/JSONKit) -* [SBJson](https://stig.github.com/json-framework/) -* [YAJL](https://lloyd.github.com/yajl/) -* [NextiveJson](https://github.com/nextive/NextiveJson) - -### ARC Support - -AFNetworking will transition its codebase to ARC in a future release. - -If you are including AFNetworking in a project that uses [Automatic Reference Counting (ARC)](http://clang.llvm.org/docs/AutomaticReferenceCounting.html) enabled, you will need to set the `-fno-objc-arc` compiler flag on all of the AFNetworking source files. To do this in Xcode, go to your active target and select the "Build Phases" tab. Now select all AFNetworking source files, press Enter, insert `-fno-objc-arc` and then "Done" to disable ARC for AFNetworking. +AFNetworking requires either [iOS 5.0](http://developer.apple.com/library/ios/#releasenotes/General/WhatsNewIniPhoneOS/Articles/iPhoneOS4.html) and above, or [Mac OS 10.7](http://developer.apple.com/library/mac/#releasenotes/MacOSX/WhatsNewInOSX/Articles/MacOSX10_6.html#//apple_ref/doc/uid/TP40008898-SW7) ([64-bit with modern Cocoa runtime](https://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtVersionsPlatforms.html)) and above. ## Credits From c3d61992979d025da70e2d86c476a5b8b7bafffd Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 10:03:27 -0700 Subject: [PATCH 12/81] Add changes for 1.0RC2 --- CHANGES | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/CHANGES b/CHANGES index 60b4cac..ddd730c 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,15 @@ += 1.0RC2 / 2012-06-26 + + * AFNetworking now requires iOS 5 / Mac OSX 10.7 or higher (Mattt Thompson) + + * AFNetworking now uses Automatic Reference Counting (ARC) (Mattt Thompson) + + * Revert implementation of `AFHTTPRequestOperation` + `+addAcceptableStatusCodes:` and `+addAcceptableContentTypes:` to use + `class_replaceMethod` with `imp_implementationWithBlock`. (Mattt Thompson) + + * Update icons for iOS example application (Mattt Thompson) + = 0.10.0 / 2012-06-26 * Add Twitter Mac Example application (Mattt Thompson) From 6e4ad945acf5e95efef3a756876b2feae647c887 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 10:05:38 -0700 Subject: [PATCH 13/81] Add Changelog entry for AFHTTPClient requests not handling cookies by default --- CHANGES | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGES b/CHANGES index ddd730c..bc7f2a8 100644 --- a/CHANGES +++ b/CHANGES @@ -8,6 +8,8 @@ `+addAcceptableStatusCodes:` and `+addAcceptableContentTypes:` to use `class_replaceMethod` with `imp_implementationWithBlock`. (Mattt Thompson) + * Update `AFHTTPClient` to not handle cookies by default (@phamsonha, Mattt Thompson) + * Update icons for iOS example application (Mattt Thompson) = 0.10.0 / 2012-06-26 From 16dc57c1fa7e3c297ae063ae9085e936c22529f9 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 26 Jun 2012 22:15:09 -0700 Subject: [PATCH 14/81] [Issue #388] Make AFURLConnectionOperation conform to NSURLConnectionDelegate and NSURLConnectionDataDelegate --- AFNetworking/AFURLConnectionOperation.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 5879526..398a474 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -75,7 +75,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; @warning Attempting to load a `file://` URL in iOS 4 may result in an `NSInvalidArgumentException`, caused by the connection returning `NSURLResponse` rather than `NSHTTPURLResponse`, which is the behavior as of iOS 5. */ -@interface AFURLConnectionOperation : NSOperation +@interface AFURLConnectionOperation : NSOperation ///------------------------------- /// @name Accessing Run Loop Modes From 2b2317907e3f4933e1eccbb80a8c9476520bdd54 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Thu, 28 Jun 2012 15:51:27 -0700 Subject: [PATCH 15/81] [Issue #379] Fixing AFHTTPRequestOperation +canProcessRequest: --- AFNetworking/AFHTTPRequestOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 7537815..267d04d 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -283,7 +283,7 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { } + (BOOL)canProcessRequest:(NSURLRequest *)request { - if (![[self class] isEqual:[AFHTTPRequestOperation class]]) { + if ([[self class] isEqual:[AFHTTPRequestOperation class]]) { return YES; } From ae340b19e9bc71aeb064af1dc0a88b5ed6277505 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 3 Jul 2012 07:20:15 -0700 Subject: [PATCH 16/81] Removing whitespace leftover in dealloc from migration --- AFNetworking/AFHTTPClient.m | 2 -- AFNetworking/AFHTTPRequestOperation.m | 2 -- AFNetworking/AFURLConnectionOperation.m | 7 ------- 3 files changed, 11 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 3bf0c11..1dd08ad 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -283,8 +283,6 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { #ifdef _SYSTEMCONFIGURATION_H [self stopMonitoringNetworkReachability]; #endif - - } - (NSString *)description { diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 267d04d..2927da7 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -128,7 +128,6 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { @dynamic response; - (void)dealloc { - if (_successCallbackQueue) { dispatch_release(_successCallbackQueue); _successCallbackQueue = NULL; @@ -138,7 +137,6 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { dispatch_release(_failureCallbackQueue); _failureCallbackQueue = NULL; } - } - (NSError *)error { diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 936a2d2..8ff123a 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -186,10 +186,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } - (void)dealloc { - - - - if (_outputStream) { [_outputStream close]; _outputStream = nil; @@ -201,9 +197,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat _backgroundTaskIdentifier = UIBackgroundTaskInvalid; } #endif - - - } - (NSString *)description { From fefd1a77ff1ba1873ae5772fbae0681a42ef3382 Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 16 Jul 2012 19:21:30 +0200 Subject: [PATCH 17/81] don't use __weak for completionBlocks. (Issue #414) We nil out the completionBlock manually in AFURLConnectionOperation. Using __weak here potentially doesn't call the set completion blocks. Restores iOS4 compatibility. Also shortens inline ifs with a ternary conditional(?:). --- AFNetworking/AFHTTPClient.m | 2 +- AFNetworking/AFHTTPRequestOperation.m | 17 +++++++----- AFNetworking/AFImageRequestOperation.m | 24 +++++++++-------- AFNetworking/AFJSONRequestOperation.m | 26 ++++++++++--------- AFNetworking/AFPropertyListRequestOperation.m | 24 +++++++++-------- AFNetworking/AFXMLRequestOperation.m | 18 +++++++------ 6 files changed, 61 insertions(+), 50 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 3bf0c11..cc7bfae 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -570,7 +570,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { for (AFHTTPRequestOperation *operation in operations) { AFCompletionBlock originalCompletionBlock = [operation.completionBlock copy]; operation.completionBlock = ^{ - dispatch_queue_t queue = operation.successCallbackQueue ? operation.successCallbackQueue : dispatch_get_main_queue(); + dispatch_queue_t queue = operation.successCallbackQueue ?: dispatch_get_main_queue(); dispatch_group_async(dispatchGroup, queue, ^{ if (originalCompletionBlock) { originalCompletionBlock(); diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 267d04d..35113fe 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -222,26 +222,29 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { - __weak AFHTTPRequestOperation *weakSelf = self; + // completion block is manually nilled out in AFURLConnectionOperation to break the retain cycle. +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-retain-cycles" self.completionBlock = ^ { - if ([weakSelf isCancelled]) { + if ([self isCancelled]) { return; } - if (weakSelf.error) { + if (self.error) { if (failure) { - dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(weakSelf, weakSelf.error); + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ + failure(self, self.error); }); } } else { if (success) { - dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(weakSelf, weakSelf.responseData); + dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ + success(self, self.responseData); }); } } }; +#pragma clang diagnostic pop } - (void)setResponseFilePath:(NSString *)responseFilePath { diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index 3b13463..e19237e 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -82,7 +82,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { dispatch_async(image_request_operation_processing_queue(), ^(void) { UIImage *processedImage = imageProcessingBlock(image); - dispatch_async(requestOperation.successCallbackQueue ? requestOperation.successCallbackQueue : dispatch_get_main_queue(), ^(void) { + dispatch_async(requestOperation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) { success(operation.request, operation.response, processedImage); }); }); @@ -113,7 +113,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { dispatch_async(image_request_operation_processing_queue(), ^(void) { NSImage *processedImage = imageProcessingBlock(image); - dispatch_async(requestOperation.successCallbackQueue ? requestOperation.successCallbackQueue : dispatch_get_main_queue(), ^(void) { + dispatch_async(requestOperation.successCallbackQueue ?: dispatch_get_main_queue(), ^(void) { success(operation.request, operation.response, processedImage); }); }); @@ -197,17 +197,18 @@ static dispatch_queue_t image_request_operation_processing_queue() { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { - __weak AFImageRequestOperation *weakSelf = self; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-retain-cycles" self.completionBlock = ^ { - if ([weakSelf isCancelled]) { + if ([self isCancelled]) { return; } dispatch_async(image_request_operation_processing_queue(), ^(void) { - if (weakSelf.error) { + if (self.error) { if (failure) { - dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(weakSelf, weakSelf.error); + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ + failure(self, self.error); }); } } else { @@ -218,15 +219,16 @@ static dispatch_queue_t image_request_operation_processing_queue() { NSImage *image = nil; #endif - image = weakSelf.responseImage; + image = self.responseImage; - dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(weakSelf, image); + dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ + success(self, image); }); } } }); - }; + }; +#pragma clang diagnostic pop } @end diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index e6968d9..f5c438e 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -96,38 +96,40 @@ static dispatch_queue_t json_request_operation_processing_queue() { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { - __weak AFJSONRequestOperation *weakSelf = self; - self.completionBlock = ^ { - if ([weakSelf isCancelled]) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-retain-cycles" + self.completionBlock = ^ { + if ([self isCancelled]) { return; } - if (weakSelf.error) { + if (self.error) { if (failure) { - dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(weakSelf, weakSelf.error); + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ + failure(self, self.error); }); } } else { dispatch_async(json_request_operation_processing_queue(), ^{ - id JSON = weakSelf.responseJSON; + id JSON = self.responseJSON; if (self.JSONError) { if (failure) { - dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(weakSelf, weakSelf.error); + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ + failure(self, self.error); }); } } else { if (success) { - dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(weakSelf, JSON); + dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ + success(self, JSON); }); } } }); } - }; + }; +#pragma clang diagnostic pop } @end diff --git a/AFNetworking/AFPropertyListRequestOperation.m b/AFNetworking/AFPropertyListRequestOperation.m index 2cf0d9d..21961d0 100644 --- a/AFNetworking/AFPropertyListRequestOperation.m +++ b/AFNetworking/AFPropertyListRequestOperation.m @@ -106,38 +106,40 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { - __weak AFPropertyListRequestOperation *weakSelf = self; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-retain-cycles" self.completionBlock = ^ { - if ([weakSelf isCancelled]) { + if ([self isCancelled]) { return; } - if (weakSelf.error) { + if (self.error) { if (failure) { - dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(weakSelf, weakSelf.error); + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ + failure(self, self.error); }); } } else { dispatch_async(property_list_request_operation_processing_queue(), ^(void) { - id propertyList = weakSelf.responsePropertyList; + id propertyList = self.responsePropertyList; if (self.propertyListError) { if (failure) { - dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(weakSelf, weakSelf.error); + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ + failure(self, self.error); }); } } else { if (success) { - dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(weakSelf, propertyList); + dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ + success(self, propertyList); }); } } }); } - }; + }; +#pragma clang diagnostic pop } @end diff --git a/AFNetworking/AFXMLRequestOperation.m b/AFNetworking/AFXMLRequestOperation.m index dbc62a1..bdc935c 100644 --- a/AFNetworking/AFXMLRequestOperation.m +++ b/AFNetworking/AFXMLRequestOperation.m @@ -138,30 +138,32 @@ static dispatch_queue_t xml_request_operation_processing_queue() { - (void)setCompletionBlockWithSuccess:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { - __weak AFXMLRequestOperation *weakSelf = self; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Warc-retain-cycles" self.completionBlock = ^ { - if ([weakSelf isCancelled]) { + if ([self isCancelled]) { return; } dispatch_async(xml_request_operation_processing_queue(), ^(void) { - NSXMLParser *XMLParser = weakSelf.responseXMLParser; + NSXMLParser *XMLParser = self.responseXMLParser; if (self.error) { if (failure) { - dispatch_async(weakSelf.failureCallbackQueue ? weakSelf.failureCallbackQueue : dispatch_get_main_queue(), ^{ - failure(weakSelf, weakSelf.error); + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ + failure(self, self.error); }); } } else { if (success) { - dispatch_async(weakSelf.successCallbackQueue ? weakSelf.successCallbackQueue : dispatch_get_main_queue(), ^{ - success(weakSelf, XMLParser); + dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ + success(self, XMLParser); }); } } }); - }; + }; +#pragma clang diagnostic pop } @end From 109037831a7cb5461d0c383bc3c348003b1a7d29 Mon Sep 17 00:00:00 2001 From: George Cox Date: Thu, 26 Jul 2012 08:05:20 -0400 Subject: [PATCH 18/81] Fixed compiler error in AFHTTPRequestOperation; #417 Casting (void *) block to (__bridge id). Required as of Xcode 4.4 --- AFNetworking/AFHTTPRequestOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 267d04d..c78e8ef 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -56,7 +56,7 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) { static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, void *block) { Method originalMethod = class_getClassMethod(klass, selector); - IMP implementation = imp_implementationWithBlock(block); + IMP implementation = imp_implementationWithBlock((__bridge id)(block)); class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); } From 2834ecc97d0c9bd44165586cf7e804c3aa6939f5 Mon Sep 17 00:00:00 2001 From: George Cox Date: Thu, 26 Jul 2012 08:17:01 -0400 Subject: [PATCH 19/81] Changed string format specifiers for NSUInteger values from %u to %lu Resolves two compiler warnings in AFHTTPRequestOperation.m and one in AFHTTPClient.m --- AFNetworking/AFHTTPClient.m | 2 +- AFNetworking/AFHTTPRequestOperation.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 3bf0c11..71a53a3 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -705,7 +705,7 @@ static inline NSString * AFMultipartFormFinalBoundary() { self.request = request; self.stringEncoding = encoding; - self.temporaryFilePath = [AFMultipartTemporaryFileDirectoryPath() stringByAppendingPathComponent:[NSString stringWithFormat:@"%u", [[self.request URL] hash]]]; + self.temporaryFilePath = [AFMultipartTemporaryFileDirectoryPath() stringByAppendingPathComponent:[NSString stringWithFormat:@"%lu", [[self.request URL] hash]]]; self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.temporaryFilePath append:NO]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 267d04d..67f516f 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -76,11 +76,11 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { } if (range.length == 1) { - [string appendFormat:@"%u", range.location]; + [string appendFormat:@"%lu", range.location]; } else { NSUInteger firstIndex = range.location; NSUInteger lastIndex = firstIndex + range.length - 1; - [string appendFormat:@"%u-%u", firstIndex, lastIndex]; + [string appendFormat:@"%lu-%lu", firstIndex, lastIndex]; } range.location = nextIndex; From 4809c774278f4b52d537e0fe6b92d73813ffe15d Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Sat, 4 Aug 2012 15:28:32 -0400 Subject: [PATCH 20/81] Updating project settings for Xcode 4.4 --- Example/AFNetworking iOS Example.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj index 987dfbf..b97693c 100644 --- a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj @@ -277,7 +277,7 @@ F8E469571395739C00DB05C8 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0430; + LastUpgradeCheck = 0440; ORGANIZATIONNAME = Gowalla; }; buildConfigurationList = F8E4695A1395739C00DB05C8 /* Build configuration list for PBXProject "AFNetworking iOS Example" */; From d02d9612dd1af84a8d9646d7b497fb83a3e2bc23 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Sat, 4 Aug 2012 15:29:00 -0400 Subject: [PATCH 21/81] Changing string format replacement tokens to suppress compiler warnings --- AFNetworking/AFHTTPClient.m | 2 +- AFNetworking/AFHTTPRequestOperation.m | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 619e7c9..1dd08ad 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -703,7 +703,7 @@ static inline NSString * AFMultipartFormFinalBoundary() { self.request = request; self.stringEncoding = encoding; - self.temporaryFilePath = [AFMultipartTemporaryFileDirectoryPath() stringByAppendingPathComponent:[NSString stringWithFormat:@"%lu", [[self.request URL] hash]]]; + self.temporaryFilePath = [AFMultipartTemporaryFileDirectoryPath() stringByAppendingPathComponent:[NSString stringWithFormat:@"%u", [[self.request URL] hash]]]; self.outputStream = [NSOutputStream outputStreamToFileAtPath:self.temporaryFilePath append:NO]; NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 67825ab..2927da7 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -76,11 +76,11 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { } if (range.length == 1) { - [string appendFormat:@"%lu", range.location]; + [string appendFormat:@"%u", range.location]; } else { NSUInteger firstIndex = range.location; NSUInteger lastIndex = firstIndex + range.length - 1; - [string appendFormat:@"%lu-%lu", firstIndex, lastIndex]; + [string appendFormat:@"%u-%u", firstIndex, lastIndex]; } range.location = nextIndex; From 7787f17469bb1edf0e4765e7ac54af7387a39b3b Mon Sep 17 00:00:00 2001 From: Leo Lobato Date: Tue, 21 Aug 2012 16:40:58 +0200 Subject: [PATCH 22/81] Fix for [Issue #237]. Check if statusCode is available on response class. --- AFNetworking/AFHTTPRequestOperation.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 23c170e..29f7254 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -127,8 +127,9 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (NSError *)error { if (self.response && !self.HTTPError) { if (![self hasAcceptableStatusCode]) { + int statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? [self.response statusCode] : 200; NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; - [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code in (%@), got %d", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), [self.response statusCode]] forKey:NSLocalizedDescriptionKey]; + [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code in (%@), got %d", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), statusCode] forKey:NSLocalizedDescriptionKey]; [userInfo setValue:self.responseString forKey:NSLocalizedRecoverySuggestionErrorKey]; [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; @@ -169,7 +170,8 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { } - (BOOL)hasAcceptableStatusCode { - return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:(NSUInteger)[self.response statusCode]]; + int statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? [self.response statusCode] : 200; + return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:statusCode]; } - (BOOL)hasAcceptableContentType { @@ -276,7 +278,8 @@ didReceiveResponse:(NSURLResponse *)response // 206 = Partial Content. long long totalContentLength = self.response.expectedContentLength; long long fileOffset = 0; - if ([self.response statusCode] != 206) { + int statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? [self.response statusCode] : 200; + if (statusCode != 206) { if ([self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey]) { [self.outputStream setProperty:[NSNumber numberWithInteger:0] forKey:NSStreamFileCurrentOffsetKey]; } else { From c0ef5c1068d0ec6cc00ecae7c37a60303dae0f63 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 21 Aug 2012 16:06:39 -0700 Subject: [PATCH 23/81] Replacing NSAutoreleasePool with @autoreleasepool --- AFNetworking/AFURLConnectionOperation.m | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 88f593b..ad462a4 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -145,9 +145,9 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat + (void)networkRequestThreadEntryPoint:(id)__unused object { do { - NSAutoreleasePool *runLoopPool = [[NSAutoreleasePool alloc] init]; - [[NSRunLoop currentRunLoop] run]; - [runLoopPool drain]; + @autoreleasepool { + [[NSRunLoop currentRunLoop] run]; + } } while (YES); } From 2d7b2f35d643eb9d5eb10ff59452a37c89f681a7 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 22 Aug 2012 10:09:24 -0700 Subject: [PATCH 24/81] [Issue #460] Removing atomic keyword in activityCount property for AFNetworkActivityIndicatorManager --- AFNetworking/AFNetworkActivityIndicatorManager.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index 5751d16..cdfe874 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -28,7 +28,7 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.17; @interface AFNetworkActivityIndicatorManager () -@property (readwrite, atomic, assign) NSInteger activityCount; +@property (readwrite, assign) NSInteger activityCount; @property (readwrite, nonatomic, retain) NSTimer *activityIndicatorVisibilityTimer; @property (readonly, getter = isNetworkActivityIndicatorVisible) BOOL networkActivityIndicatorVisible; @@ -52,6 +52,10 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.17; return _sharedManager; } ++ (NSSet *)keyPathsForValuesAffectingIsNetworkActivityIndicatorVisible { + return [NSSet setWithObject:@"activityCount"]; +} + - (id)init { self = [super init]; if (!self) { @@ -124,10 +128,6 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.17; [self updateNetworkActivityIndicatorVisibilityDelayed]; } -+ (NSSet *)keyPathsForValuesAffectingIsNetworkActivityIndicatorVisible { - return [NSSet setWithObject:@"activityCount"]; -} - @end #endif From 706fbe473d6118db12f0c15258d619d6de2e67bc Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 22 Aug 2012 11:31:49 -0700 Subject: [PATCH 25/81] [Issue #469] Optimizing calculation of finished operations in batch progress callback --- AFNetworking/AFHTTPClient.m | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 5602822..53d598a 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -584,9 +584,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { }); dispatch_release(dispatchGroup); }]; - - NSPredicate *finishedOperationPredicate = [NSPredicate predicateWithFormat:@"isFinished == YES"]; - + for (AFHTTPRequestOperation *operation in operations) { AFCompletionBlock originalCompletionBlock = [[operation.completionBlock copy] autorelease]; operation.completionBlock = ^{ @@ -596,8 +594,15 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { originalCompletionBlock(); } + __block NSUInteger numberOfCompletedOperations = 0; + [operations enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { + if ([(NSOperation *)obj isFinished]) { + numberOfCompletedOperations++; + } + }]; + if (progressBlock) { - progressBlock([[operations filteredArrayUsingPredicate:finishedOperationPredicate] count], [operations count]); + progressBlock(numberOfCompletedOperations, [operations count]); } dispatch_group_leave(dispatchGroup); From 72a85e1ee69f1c19c7b81d3db35edea8dbed6334 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 22 Aug 2012 11:32:59 -0700 Subject: [PATCH 26/81] Renaming numberOfCompletedOperations variable in progress block to numberOfFinishedOperations --- AFNetworking/AFHTTPClient.h | 4 ++-- AFNetworking/AFHTTPClient.m | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index c70df00..879f727 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -362,7 +362,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @discussion Operations are created by passing the specified `NSURLRequest` objects in `requests`, using `-HTTPRequestOperationWithRequest:success:failure:`, with `nil` for both the `success` and `failure` parameters. */ - (void)enqueueBatchOfHTTPRequestOperationsWithRequests:(NSArray *)requests - progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock + progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock completionBlock:(void (^)(NSArray *operations))completionBlock; /** @@ -373,7 +373,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @param completionBlock A block object to be executed upon the completion of all of the request operations in the batch. This block has no return value and takes a single argument: the batched request operations. */ - (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations - progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock + progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock completionBlock:(void (^)(NSArray *operations))completionBlock; ///--------------------------- diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 53d598a..53d90ef 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -559,7 +559,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { } - (void)enqueueBatchOfHTTPRequestOperationsWithRequests:(NSArray *)requests - progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock + progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock completionBlock:(void (^)(NSArray *operations))completionBlock { NSMutableArray *mutableOperations = [NSMutableArray array]; @@ -572,7 +572,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { } - (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations - progressBlock:(void (^)(NSUInteger numberOfCompletedOperations, NSUInteger totalNumberOfOperations))progressBlock + progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock completionBlock:(void (^)(NSArray *operations))completionBlock { __block dispatch_group_t dispatchGroup = dispatch_group_create(); @@ -594,15 +594,15 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { originalCompletionBlock(); } - __block NSUInteger numberOfCompletedOperations = 0; + __block NSUInteger numberOfFinishedOperations = 0; [operations enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { if ([(NSOperation *)obj isFinished]) { - numberOfCompletedOperations++; + numberOfFinishedOperations++; } }]; if (progressBlock) { - progressBlock(numberOfCompletedOperations, [operations count]); + progressBlock(numberOfFinishedOperations, [operations count]); } dispatch_group_leave(dispatchGroup); From 384df960acdf8e24fcd5bd0981f51452e4d2f5ec Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 22 Aug 2012 11:46:03 -0700 Subject: [PATCH 27/81] Converting int to NSUInteger for instances of manually checking status code in AFHTTPRequestOperation --- AFNetworking/AFHTTPRequestOperation.m | 8 ++++---- AFNetworking/AFURLConnectionOperation.h | 4 +--- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 29f7254..a26984b 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -127,7 +127,7 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (NSError *)error { if (self.response && !self.HTTPError) { if (![self hasAcceptableStatusCode]) { - int statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? [self.response statusCode] : 200; + NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code in (%@), got %d", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), statusCode] forKey:NSLocalizedDescriptionKey]; [userInfo setValue:self.responseString forKey:NSLocalizedRecoverySuggestionErrorKey]; @@ -170,7 +170,7 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { } - (BOOL)hasAcceptableStatusCode { - int statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? [self.response statusCode] : 200; + NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:statusCode]; } @@ -278,7 +278,7 @@ didReceiveResponse:(NSURLResponse *)response // 206 = Partial Content. long long totalContentLength = self.response.expectedContentLength; long long fileOffset = 0; - int statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? [self.response statusCode] : 200; + NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; if (statusCode != 206) { if ([self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey]) { [self.outputStream setProperty:[NSNumber numberWithInteger:0] forKey:NSStreamFileCurrentOffsetKey]; @@ -287,7 +287,7 @@ didReceiveResponse:(NSURLResponse *)response self.outputStream = [NSOutputStream outputStreamToMemory]; } } - }else { + } else { NSString *contentRange = [self.response.allHeaderFields valueForKey:@"Content-Range"]; if ([contentRange hasPrefix:@"bytes"]) { NSArray *bytes = [contentRange componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" -/"]]; diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index ace5a86..4fa20ed 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -86,9 +86,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; - `-copy` and `-copyWithZone:` return a new operation with the `NSURLRequest` of the original. So rather than an exact copy of the operation at that particular instant, the copying mechanism returns a completely new instance, which can be useful for retrying operations. - A copy of an operation will not include the `outputStream` of the original. - - Operation copies do not include `completionBlock`. `completionBlock` often strongly captures a reference to `self`, which, perhaps surprisingly, would otherwise point to the _original_ operation when copied. - - @warning Attempting to load a `file://` URL in iOS 4 may result in an `NSInvalidArgumentException`, caused by the connection returning `NSURLResponse` rather than `NSHTTPURLResponse`, which is the behavior as of iOS 5. + - Operation copies do not include `completionBlock`. `completionBlock` often strongly captures a reference to `self`, which, perhaps surprisingly, would otherwise point to the _original_ operation when copied. */ @interface AFURLConnectionOperation : NSOperation From d863759f529f60bc937ff137fbdd1010f1d2bb05 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 22 Aug 2012 11:53:19 -0700 Subject: [PATCH 28/81] Reformatting and documenting AFHTTPRequestOperation -connection:didReceiveResponse: --- AFNetworking/AFHTTPRequestOperation.m | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index a26984b..cf10ba8 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -275,11 +275,21 @@ didReceiveResponse:(NSURLResponse *)response { self.response = (NSHTTPURLResponse *)response; - // 206 = Partial Content. + // Set Content-Range header if status code of response is 206 (Partial Content) + // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.2.7 long long totalContentLength = self.response.expectedContentLength; long long fileOffset = 0; NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; - if (statusCode != 206) { + if (statusCode == 206) { + NSString *contentRange = [self.response.allHeaderFields valueForKey:@"Content-Range"]; + if ([contentRange hasPrefix:@"bytes"]) { + NSArray *byteRanges = [contentRange componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" -/"]]; + if ([byteRanges count] == 4) { + fileOffset = [[byteRanges objectAtIndex:1] longLongValue]; + totalContentLength = [[byteRanges objectAtIndex:2] longLongValue] ?: -1; // if this is "*", it's converted to 0, but -1 is default. + } + } + } else { if ([self.outputStream propertyForKey:NSStreamFileCurrentOffsetKey]) { [self.outputStream setProperty:[NSNumber numberWithInteger:0] forKey:NSStreamFileCurrentOffsetKey]; } else { @@ -287,19 +297,11 @@ didReceiveResponse:(NSURLResponse *)response self.outputStream = [NSOutputStream outputStreamToMemory]; } } - } else { - NSString *contentRange = [self.response.allHeaderFields valueForKey:@"Content-Range"]; - if ([contentRange hasPrefix:@"bytes"]) { - NSArray *bytes = [contentRange componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" -/"]]; - if ([bytes count] == 4) { - fileOffset = [[bytes objectAtIndex:1] longLongValue]; - totalContentLength = [[bytes objectAtIndex:2] longLongValue] ?: -1; // if this is *, it's converted to 0, but -1 is default. - } - } - } + self.offsetContentLength = MAX(fileOffset, 0); self.totalContentLength = totalContentLength; + [self.outputStream open]; } From 88b52b0f88afd43440ab77cde6397ba1a50138ed Mon Sep 17 00:00:00 2001 From: Matthias Wessendorf Date: Thu, 23 Aug 2012 19:01:30 +0300 Subject: [PATCH 29/81] fixed type( resonse VS response) --- AFNetworking/AFHTTPClient.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 879f727..2e590ff 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -323,7 +323,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @param request The request object to be loaded asynchronously during execution of the operation. @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. - @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. + @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. */ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success @@ -386,7 +386,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @param path The path to be appended to the HTTP client's base URL and used as the request URL. @param parameters The parameters to be encoded and appended as the query string for the request URL. @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. - @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. + @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. @see HTTPRequestOperationWithRequest:success:failure */ @@ -401,7 +401,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @param path The path to be appended to the HTTP client's base URL and used as the request URL. @param parameters The parameters to be encoded and set in the request HTTP body. @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. - @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. + @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. @see HTTPRequestOperationWithRequest:success:failure */ @@ -416,7 +416,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @param path The path to be appended to the HTTP client's base URL and used as the request URL. @param parameters The parameters to be encoded and set in the request HTTP body. @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. - @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. + @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. @see HTTPRequestOperationWithRequest:success:failure */ @@ -431,7 +431,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @param path The path to be appended to the HTTP client's base URL and used as the request URL. @param parameters The parameters to be encoded and appended as the query string for the request URL. @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. - @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. + @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. @see HTTPRequestOperationWithRequest:success:failure */ @@ -446,7 +446,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete @param path The path to be appended to the HTTP client's base URL and used as the request URL. @param parameters The parameters to be encoded and set in the request HTTP body. @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. - @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. + @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. @see HTTPRequestOperationWithRequest:success:failure */ From 1136bc5e2f8493cab0db582b336581c18d01e3dc Mon Sep 17 00:00:00 2001 From: Gareth du Plooy Date: Thu, 23 Aug 2012 11:59:54 -0500 Subject: [PATCH 30/81] Calling downloadProgress no longer casting [data length] to (long long) AFURLConnectionOperationProgressBlock specifies "bytes" as an NSInteger. Master was casting [data length] as a long long, resulting in compilation errors if attempting to compile with more strict complication rules. Only the totalBytes and totalBytesExpected are specified as (and correctly called with) long long values. --- AFNetworking/AFURLConnectionOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index ad462a4..e668aa2 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -563,7 +563,7 @@ didReceiveResponse:(NSURLResponse *)response if (self.downloadProgress) { dispatch_async(dispatch_get_main_queue(), ^{ - self.downloadProgress((long long)[data length], self.totalBytesRead, self.response.expectedContentLength); + self.downloadProgress([data length], self.totalBytesRead, self.response.expectedContentLength); }); } } From dd0e659e09d34288bbe73bd80ff3e232a9bf901e Mon Sep 17 00:00:00 2001 From: Steven Fisher Date: Thu, 23 Aug 2012 10:08:12 -0700 Subject: [PATCH 31/81] Spelling corrections. --- AFNetworking/AFHTTPClient.h | 4 ++-- AFNetworking/AFHTTPRequestOperation.h | 12 ++++++------ AFNetworking/AFJSONRequestOperation.h | 2 +- AFNetworking/AFURLConnectionOperation.h | 6 +++--- AFNetworking/AFXMLRequestOperation.h | 2 +- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 2e590ff..84d5965 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -114,7 +114,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete ## URL Construction Using Relative Paths - Both `requestWithMethod:path:parameters` and `multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` construct URLs from the path relative to the `baseURL`, using `NSURL +URLWithString:relativeToURL:`. Below are a few examples of how `baseURL` and relative paths interract: + Both `requestWithMethod:path:parameters` and `multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` construct URLs from the path relative to the `baseURL`, using `NSURL +URLWithString:relativeToURL:`. Below are a few examples of how `baseURL` and relative paths interact: NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"]; [NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo @@ -138,7 +138,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete ///--------------------------------------- /** - The url used as the base for paths specified in methods such as `getPath:parameteres:success:failure` + The url used as the base for paths specified in methods such as `getPath:parameters:success:failure` */ @property (readonly, nonatomic, retain) NSURL *baseURL; diff --git a/AFNetworking/AFHTTPRequestOperation.h b/AFNetworking/AFHTTPRequestOperation.h index 891cd0f..608a6cb 100644 --- a/AFNetworking/AFHTTPRequestOperation.h +++ b/AFNetworking/AFHTTPRequestOperation.h @@ -66,9 +66,9 @@ extern NSSet * AFContentTypesFromHTTPHeader(NSString *string); */ @property (nonatomic, assign) dispatch_queue_t failureCallbackQueue; -///------------------------------------------------------------- -/// @name Managing Accceptable HTTP Status Codes & Content Types -///------------------------------------------------------------- +///------------------------------------------------------------ +/// @name Managing Acceptable HTTP Status Codes & Content Types +///------------------------------------------------------------ /** Returns an `NSIndexSet` object containing the ranges of acceptable HTTP status codes. When non-`nil`, the operation will set the `error` property to an error in `AFErrorDomain`. See http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html @@ -78,7 +78,7 @@ extern NSSet * AFContentTypesFromHTTPHeader(NSString *string); + (NSIndexSet *)acceptableStatusCodes; /** - Adds status codes to the set of acceptable HTTP status codes returned by `+acceptableStatusCodes` in subsequent calls by this class and its descendents. + Adds status codes to the set of acceptable HTTP status codes returned by `+acceptableStatusCodes` in subsequent calls by this class and its descendants. @param statusCodes The status codes to be added to the set of acceptable HTTP status codes */ @@ -92,7 +92,7 @@ extern NSSet * AFContentTypesFromHTTPHeader(NSString *string); + (NSSet *)acceptableContentTypes; /** - Adds content types to the set of acceptable MIME types returned by `+acceptableContentTypes` in subsequent calls by this class and its descendents. + Adds content types to the set of acceptable MIME types returned by `+acceptableContentTypes` in subsequent calls by this class and its descendants. @param contentTypes The content types to be added to the set of acceptable MIME types */ @@ -118,7 +118,7 @@ extern NSSet * AFContentTypesFromHTTPHeader(NSString *string); Sets the `completionBlock` property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If `error` returns a value, which can be caused by an unacceptable status code or content type, then `failure` is executed. Otherwise, `success` is executed. @param success The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request. - @param failure The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occured during the request. + @param failure The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occurred during the request. @discussion This method should be overridden in subclasses in order to specify the response object passed into the success block. */ diff --git a/AFNetworking/AFJSONRequestOperation.h b/AFNetworking/AFJSONRequestOperation.h index a1191f9..84746f2 100644 --- a/AFNetworking/AFJSONRequestOperation.h +++ b/AFNetworking/AFJSONRequestOperation.h @@ -55,7 +55,7 @@ @param urlRequest The request object to be loaded asynchronously during execution of the operation @param success A block object to be executed when the operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the JSON object created from the response data of request. - @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data as JSON. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred. + @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data as JSON. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred. @return A new JSON request operation */ diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 4fa20ed..ab08518 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -23,7 +23,7 @@ #import /** - Indicates an error occured in AFNetworking. + Indicates an error occurred in AFNetworking. @discussion Error codes for AFNetworkingErrorDomain correspond to codes in NSURLErrorDomain. */ @@ -61,7 +61,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; - `connection:canAuthenticateAgainstProtectionSpace:` - `connection:didReceiveAuthenticationChallenge:` - If any of these methods are overriden in a subclass, they _must_ call the `super` implementation first. + If any of these methods are overridden in a subclass, they _must_ call the `super` implementation first. ## Class Constructors @@ -114,7 +114,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; @property (readonly, nonatomic, retain) NSURLResponse *response; /** - The error, if any, that occured in the lifecycle of the request. + The error, if any, that occurred in the lifecycle of the request. */ @property (readonly, nonatomic, retain) NSError *error; diff --git a/AFNetworking/AFXMLRequestOperation.h b/AFNetworking/AFXMLRequestOperation.h index 0beb677..876c127 100644 --- a/AFNetworking/AFXMLRequestOperation.h +++ b/AFNetworking/AFXMLRequestOperation.h @@ -77,7 +77,7 @@ @param urlRequest The request object to be loaded asynchronously during execution of the operation @param success A block object to be executed when the operation finishes successfully. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the XML document created from the response data of request. - @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the resonse data as XML. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred. + @param failure A block object to be executed when the operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data as XML. This block has no return value and takes three arguments: the request sent from the client, the response received from the server, and the error describing the network or parsing error that occurred. @return A new XML request operation */ From 13ec70cc8f5bc5acd3d579c60704e7a8638abc24 Mon Sep 17 00:00:00 2001 From: Gareth du Plooy Date: Thu, 23 Aug 2012 13:15:47 -0500 Subject: [PATCH 32/81] AFURLConnectionOperationProgressBlock bytes now NSUinteger This seems to be the most proper data type for this parameter. What gets passed in for uploadProgress is an NSInteger (guaranteed to be positive), and [NSData length], which is an NSUInteger, for downloadProgress. --- AFNetworking/AFURLConnectionOperation.h | 4 ++-- AFNetworking/AFURLConnectionOperation.m | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 4fa20ed..127747c 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -216,7 +216,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; @see setDownloadProgressBlock */ -- (void)setUploadProgressBlock:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block; +- (void)setUploadProgressBlock:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block; /** Sets a callback to be called when an undetermined number of bytes have been downloaded from the server. @@ -225,7 +225,7 @@ extern NSString * const AFNetworkingOperationDidFinishNotification; @see setUploadProgressBlock */ -- (void)setDownloadProgressBlock:(void (^)(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block; +- (void)setDownloadProgressBlock:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block; ///------------------------------------------------- /// @name Setting NSURLConnection Delegate Callbacks diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index e668aa2..98a0343 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -47,7 +47,7 @@ NSString * const AFNetworkingErrorDomain = @"com.alamofire.networking.error"; NSString * const AFNetworkingOperationDidStartNotification = @"com.alamofire.networking.operation.start"; NSString * const AFNetworkingOperationDidFinishNotification = @"com.alamofire.networking.operation.finish"; -typedef void (^AFURLConnectionOperationProgressBlock)(NSInteger bytes, long long totalBytes, long long totalBytesExpected); +typedef void (^AFURLConnectionOperationProgressBlock)(NSUInteger bytes, long long totalBytes, long long totalBytesExpected); typedef BOOL (^AFURLConnectionOperationAuthenticationAgainstProtectionSpaceBlock)(NSURLConnection *connection, NSURLProtectionSpace *protectionSpace); typedef void (^AFURLConnectionOperationAuthenticationChallengeBlock)(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge); typedef NSCachedURLResponse * (^AFURLConnectionOperationCacheResponseBlock)(NSURLConnection *connection, NSCachedURLResponse *cachedResponse); @@ -287,11 +287,11 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } #endif -- (void)setUploadProgressBlock:(void (^)(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block { +- (void)setUploadProgressBlock:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block { self.uploadProgress = block; } -- (void)setDownloadProgressBlock:(void (^)(NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block { +- (void)setDownloadProgressBlock:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block { self.downloadProgress = block; } From 3ac1eb103127fafa9eb04b1cdf6567c8734fff76 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 09:29:47 -0700 Subject: [PATCH 33/81] Using more idiomatic ?: for success/failureCallbackQueue fallbacks --- AFNetworking/AFJSONRequestOperation.m | 6 +++--- AFNetworking/AFPropertyListRequestOperation.m | 6 +++--- AFNetworking/AFXMLRequestOperation.m | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index bcdcb7f..dc4a542 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -109,7 +109,7 @@ static dispatch_queue_t json_request_operation_processing_queue() { if (self.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ failure(self, self.error); }); } @@ -119,13 +119,13 @@ static dispatch_queue_t json_request_operation_processing_queue() { if (self.JSONError) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ failure(self, self.error); }); } } else { if (success) { - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.successCallbackQueue ? : dispatch_get_main_queue(), ^{ success(self, JSON); }); } diff --git a/AFNetworking/AFPropertyListRequestOperation.m b/AFNetworking/AFPropertyListRequestOperation.m index ecca1af..f8fa064 100644 --- a/AFNetworking/AFPropertyListRequestOperation.m +++ b/AFNetworking/AFPropertyListRequestOperation.m @@ -118,7 +118,7 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { if (self.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ failure(self, self.error); }); } @@ -128,13 +128,13 @@ static dispatch_queue_t property_list_request_operation_processing_queue() { if (self.propertyListError) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ failure(self, self.error); }); } } else { if (success) { - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ success(self, propertyList); }); } diff --git a/AFNetworking/AFXMLRequestOperation.m b/AFNetworking/AFXMLRequestOperation.m index f40cacb..f71efd8 100644 --- a/AFNetworking/AFXMLRequestOperation.m +++ b/AFNetworking/AFXMLRequestOperation.m @@ -159,13 +159,13 @@ static dispatch_queue_t xml_request_operation_processing_queue() { if (self.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ failure(self, self.error); }); } } else { if (success) { - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ success(self, XMLParser); }); } From d7412b7ae0f8654b03d1be673627d4b479ed0dee Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 10:04:16 -0700 Subject: [PATCH 34/81] Adding prefix_header_contents declaration in Podspec Adding missing dot to end of summary Updating Scott Raymond's e-mail address --- AFNetworking.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index 3e4dda5..904be11 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -2,11 +2,11 @@ Pod::Spec.new do |s| s.name = 'AFNetworking' s.version = '0.10.0' s.license = 'MIT' - s.summary = 'A delightful iOS and OS X networking framework' + s.summary = 'A delightful iOS and OS X networking framework.' s.homepage = 'https://github.com/AFNetworking/AFNetworking' - s.authors = {'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@gowalla.com'} + s.authors = {'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@scottraymond.net'} s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '0.10.0' } s.source_files = 'AFNetworking' - s.clean_paths = ['iOS Example', 'Mac Example', 'AFNetworking.xcworkspace'] s.framework = 'SystemConfiguration' + s.prefix_header_contents = "#import " end From bb8aee4a4f5dba9f947d9bd11fc48e4ed6d14aa0 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 10:48:41 -0700 Subject: [PATCH 35/81] [Issue #444] Reducing number of legal characters to escape in query string parameters --- AFNetworking/AFHTTPClient.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 53d90ef..144967d 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -93,9 +93,10 @@ static NSString * AFBase64EncodedStringFromString(NSString *string) { } NSString * AFURLEncodedStringFromStringWithEncoding(NSString *string, NSStringEncoding encoding) { - static NSString * const kAFLegalCharactersToBeEscaped = @"?!@#$^&%*+=,:;'\"`<>()[]{}/\\|~ "; + // Escape characters that are legal in URIs, but have unintentional semantic significance when used in a query string parameter + static NSString * const kAFLegalCharactersToBeEscaped = @":/.?&=;+!@$()~"; - return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)) autorelease]; + return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)) autorelease]; } #pragma mark - From e1995eae55106a5d61c160cc1f60022555860da2 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 10:49:55 -0700 Subject: [PATCH 36/81] Significant refactoring and renaming of internal query string serialization functions. Query String parameter components are now pairs, comprised of a field and a corresponding value. --- AFNetworking/AFHTTPClient.m | 88 +++++++++++++++---------------------- 1 file changed, 35 insertions(+), 53 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 144967d..d91288e 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -92,106 +92,88 @@ static NSString * AFBase64EncodedStringFromString(NSString *string) { return [[[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding] autorelease]; } -NSString * AFURLEncodedStringFromStringWithEncoding(NSString *string, NSStringEncoding encoding) { +NSString * AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(NSString *string, NSStringEncoding encoding) { // Escape characters that are legal in URIs, but have unintentional semantic significance when used in a query string parameter static NSString * const kAFLegalCharactersToBeEscaped = @":/.?&=;+!@$()~"; - - return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)) autorelease]; + + return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)) autorelease]; } #pragma mark - -@interface AFQueryStringComponent : NSObject { -@private - NSString *_key; - NSString *_value; -} - -@property (readwrite, nonatomic, retain) id key; +@interface AFQueryStringPair : NSObject +@property (readwrite, nonatomic, retain) id field; @property (readwrite, nonatomic, retain) id value; -- (id)initWithKey:(id)key value:(id)value; +- (id)initWithField:(id)field value:(id)value; - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding; @end -@implementation AFQueryStringComponent -@synthesize key = _key; +@implementation AFQueryStringPair +@synthesize field = _field; @synthesize value = _value; -- (id)initWithKey:(id)key value:(id)value { +- (id)initWithField:(id)field value:(id)value { self = [super init]; if (!self) { return nil; } - self.key = key; + self.field = field; self.value = value; return self; } - (void)dealloc { - [_key release]; + [_field release]; [_value release]; [super dealloc]; } - (NSString *)URLEncodedStringValueWithEncoding:(NSStringEncoding)stringEncoding { - return [NSString stringWithFormat:@"%@=%@", self.key, AFURLEncodedStringFromStringWithEncoding([self.value description], stringEncoding)]; + return [NSString stringWithFormat:@"%@=%@", AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(self.field, stringEncoding), AFPercentEscapedQueryStringPairMemberFromStringWithEncoding([self.value description], stringEncoding)]; } @end #pragma mark - -extern NSArray * AFQueryStringComponentsFromKeyAndValue(NSString *key, id value); -extern NSArray * AFQueryStringComponentsFromKeyAndDictionaryValue(NSString *key, NSDictionary *value); -extern NSArray * AFQueryStringComponentsFromKeyAndArrayValue(NSString *key, NSArray *value); +extern NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary); +extern NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value); NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *parameters, NSStringEncoding stringEncoding) { - NSMutableArray *mutableComponents = [NSMutableArray array]; - for (AFQueryStringComponent *component in AFQueryStringComponentsFromKeyAndValue(nil, parameters)) { - [mutableComponents addObject:[component URLEncodedStringValueWithEncoding:stringEncoding]]; + NSMutableArray *mutablePairs = [NSMutableArray array]; + for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) { + [mutablePairs addObject:[pair URLEncodedStringValueWithEncoding:stringEncoding]]; } - return [mutableComponents componentsJoinedByString:@"&"]; + return [mutablePairs componentsJoinedByString:@"&"]; } -NSArray * AFQueryStringComponentsFromKeyAndValue(NSString *key, id value) { +NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary) { + return AFQueryStringPairsFromKeyAndValue(nil, dictionary); +} + +NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) { NSMutableArray *mutableQueryStringComponents = [NSMutableArray array]; if([value isKindOfClass:[NSDictionary class]]) { - [mutableQueryStringComponents addObjectsFromArray:AFQueryStringComponentsFromKeyAndDictionaryValue(key, value)]; + [value enumerateKeysAndObjectsUsingBlock:^(id nestedKey, id nestedValue, BOOL *stop) { + [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)]; + }]; } else if([value isKindOfClass:[NSArray class]]) { - [mutableQueryStringComponents addObjectsFromArray:AFQueryStringComponentsFromKeyAndArrayValue(key, value)]; + [value enumerateObjectsUsingBlock:^(id nestedValue, NSUInteger idx, BOOL *stop) { + [mutableQueryStringComponents addObjectsFromArray:AFQueryStringPairsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)]; + }]; } else { - [mutableQueryStringComponents addObject:[[[AFQueryStringComponent alloc] initWithKey:key value:value] autorelease]]; + [mutableQueryStringComponents addObject:[[[AFQueryStringPair alloc] initWithField:key value:value] autorelease]]; } return mutableQueryStringComponents; } -NSArray * AFQueryStringComponentsFromKeyAndDictionaryValue(NSString *key, NSDictionary *value){ - NSMutableArray *mutableQueryStringComponents = [NSMutableArray array]; - - [value enumerateKeysAndObjectsUsingBlock:^(id nestedKey, id nestedValue, BOOL *stop) { - [mutableQueryStringComponents addObjectsFromArray:AFQueryStringComponentsFromKeyAndValue((key ? [NSString stringWithFormat:@"%@[%@]", key, nestedKey] : nestedKey), nestedValue)]; - }]; - - return mutableQueryStringComponents; -} - -NSArray * AFQueryStringComponentsFromKeyAndArrayValue(NSString *key, NSArray *value) { - NSMutableArray *mutableQueryStringComponents = [NSMutableArray array]; - - [value enumerateObjectsUsingBlock:^(id nestedValue, NSUInteger idx, BOOL *stop) { - [mutableQueryStringComponents addObjectsFromArray:AFQueryStringComponentsFromKeyAndValue([NSString stringWithFormat:@"%@[]", key], nestedValue)]; - }]; - - return mutableQueryStringComponents; -} - static NSString * AFJSONStringFromParameters(NSDictionary *parameters) { NSError *error = nil; NSData *JSONData = AFJSONEncode(parameters, &error); @@ -497,16 +479,16 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { __block AFMultipartFormData *formData = [[[AFMultipartFormData alloc] initWithURLRequest:request stringEncoding:self.stringEncoding] autorelease]; if (parameters) { - for (AFQueryStringComponent *component in AFQueryStringComponentsFromKeyAndValue(nil, parameters)) { + for (AFQueryStringPair *pair in AFQueryStringPairsFromDictionary(parameters)) { NSData *data = nil; - if ([component.value isKindOfClass:[NSData class]]) { - data = component.value; + if ([pair.value isKindOfClass:[NSData class]]) { + data = pair.value; } else { - data = [[component.value description] dataUsingEncoding:self.stringEncoding]; + data = [[pair.value description] dataUsingEncoding:self.stringEncoding]; } if (data) { - [formData appendPartWithFormData:data name:[component.key description]]; + [formData appendPartWithFormData:data name:[pair.field description]]; } } } From 0aeaa60a23b7ac5e41301bb570982ef5a6ab2722 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 10:55:34 -0700 Subject: [PATCH 37/81] Removing extern declaration for AFURLEncodedStringFromStringWithEncoding function (CFURLCreateStringByAddingPercentEscapes should be used instead) --- AFNetworking/AFHTTPClient.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 84d5965..296da7a 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -58,18 +58,6 @@ typedef enum { AFPropertyListParameterEncoding, } AFHTTPClientParameterEncoding; -/** - Returns a string, replacing certain characters with the equivalent percent escape sequence based on the specified encoding. - - @param string The string to URL encode - @param encoding The encoding to use for the replacement. If you are uncertain of the correct encoding, you should use UTF-8 (NSUTF8StringEncoding), which is the encoding designated by RFC 3986 as the correct encoding for use in URLs. - - @discussion The characters escaped are all characters that are not legal URL characters (based on RFC 3986), including any whitespace, punctuation, or special characters. - - @return A URL-encoded string. If it does not need to be modified (no percent escape sequences are missing), this function may merely return string argument. - */ -extern NSString * AFURLEncodedStringFromStringWithEncoding(NSString *string, NSStringEncoding encoding); - /** Returns a query string constructed by a set of parameters, using the specified encoding. From 4b26f26c2d58785aebd30425839c8331864ae665 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 10:57:59 -0700 Subject: [PATCH 38/81] Updating documentation for AFQueryStringFromParametersWithEncoding --- AFNetworking/AFHTTPClient.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 296da7a..e96592b 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -62,14 +62,13 @@ typedef enum { Returns a query string constructed by a set of parameters, using the specified encoding. @param parameters The parameters used to construct the query string - @param encoding The encoding to use in constructing the query string. If you are uncertain of the correct encoding, you should use UTF-8 (NSUTF8StringEncoding), which is the encoding designated by RFC 3986 as the correct encoding for use in URLs. + @param encoding The encoding to use in constructing the query string. If you are uncertain of the correct encoding, you should use UTF-8 (`NSUTF8StringEncoding`), which is the encoding designated by RFC 3986 as the correct encoding for use in URLs. - @discussion Query strings are constructed by collecting each key-value pair, URL-encoding a string representation of the key-value pair, and then joining the components with "&". + @discussion Query strings are constructed by collecting each key-value pair, percent escaping a string representation of the key-value pair, and then joining the pairs with "&". + If a query string pair has a an `NSArray` for its value, each member of the array will be represented in the format `field[]=value1&field[]value2`. Otherwise, the pair will be formatted as "field=value". String representations of both keys and values are derived using the `-description` method. The constructed query string does not include the ? character used to delimit the query component. - If a key-value pair has a an `NSArray` for its value, each member of the array will be represented in the format `key[]=value1&key[]value2`. Otherwise, the key-value pair will be formatted as "key=value". String representations of both keys and values are derived using the `-description` method. The constructed query string does not include the ? character used to delimit the query component. - - @return A URL-encoded query string + @return A percent-escaped query string */ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *parameters, NSStringEncoding encoding); From 730c35926ad926cab80d053c895f3444daa85f23 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 11:57:25 -0700 Subject: [PATCH 39/81] Improving default AFHTTPClient User-Agent strings --- AFNetworking/AFHTTPClient.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index d91288e..2257cb0 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -257,14 +257,14 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { // Accept-Language HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 NSString *preferredLanguageCodes = [[NSLocale preferredLanguages] componentsJoinedByString:@", "]; [self setDefaultHeader:@"Accept-Language" value:[NSString stringWithFormat:@"%@, en-us;q=0.8", preferredLanguageCodes]]; - + #if __IPHONE_OS_VERSION_MIN_REQUIRED // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 - [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@, %@ %@, %@, Scale/%f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], @"unknown", [[UIDevice currentDevice] systemName], [[UIDevice currentDevice] systemVersion], [[UIDevice currentDevice] model], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0)]]; + [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]]; #elif __MAC_OS_X_VERSION_MIN_REQUIRED - [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], @"unknown"]]; + [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]]; #endif - + #ifdef _SYSTEMCONFIGURATION_H self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown; [self startMonitoringNetworkReachability]; From ed94ddf7b09263fcc7104e936a7ae1d751199fe7 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 12:24:58 -0700 Subject: [PATCH 40/81] [Issue #472] Defining error keys for failing request and response to be included in NSError created in AFHTTPRequestOperation Refactoring AFHTTPRequestOperation error handling code --- AFNetworking/AFHTTPRequestOperation.m | 25 ++++++++++++++----------- AFNetworking/AFURLConnectionOperation.h | 10 ++++++++++ AFNetworking/AFURLConnectionOperation.m | 4 +++- 3 files changed, 27 insertions(+), 12 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index cf10ba8..26b0eb0 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -126,21 +126,24 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (NSError *)error { if (self.response && !self.HTTPError) { - if (![self hasAcceptableStatusCode]) { - NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; + if (![self hasAcceptableStatusCode] || ![self hasAcceptableContentType]) { NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; - [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code in (%@), got %d", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), statusCode] forKey:NSLocalizedDescriptionKey]; [userInfo setValue:self.responseString forKey:NSLocalizedRecoverySuggestionErrorKey]; [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; + [userInfo setValue:self.request forKey:AFNetworkingOperationFailingURLRequestErrorKey]; + [userInfo setValue:self.response forKey:AFNetworkingOperationFailingURLResponseErrorKey]; - self.HTTPError = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo] autorelease]; - } else if ([self.responseData length] > 0 && ![self hasAcceptableContentType]) { // Don't invalidate content type if there is no content - NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; - [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected content type %@, got %@", nil), [[self class] acceptableContentTypes], [self.response MIMEType]] forKey:NSLocalizedDescriptionKey]; - [userInfo setValue:self.responseString forKey:NSLocalizedRecoverySuggestionErrorKey]; - [userInfo setValue:[self.request URL] forKey:NSURLErrorFailingURLErrorKey]; - - self.HTTPError = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo] autorelease]; + if (![self hasAcceptableStatusCode]) { + NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; + [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected status code in (%@), got %d", nil), AFStringFromIndexSet([[self class] acceptableStatusCodes]), statusCode] forKey:NSLocalizedDescriptionKey]; + self.HTTPError = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadServerResponse userInfo:userInfo] autorelease]; + } else if (![self hasAcceptableContentType]) { + // Don't invalidate content type if there is no content + if ([self.responseData length] > 0) { + [userInfo setValue:[NSString stringWithFormat:NSLocalizedString(@"Expected content type %@, got %@", nil), [[self class] acceptableContentTypes], [self.response MIMEType]] forKey:NSLocalizedDescriptionKey]; + self.HTTPError = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorCannotDecodeContentData userInfo:userInfo] autorelease]; + } + } } } diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 358b57a..ad7ace8 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -29,6 +29,16 @@ */ extern NSString * const AFNetworkingErrorDomain; +/** + The corresponding value is an `NSURLRequest` containing the request of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`. + */ +extern NSString * const AFNetworkingOperationFailingURLRequestErrorKey; + +/** + The corresponding value is an `NSURLResponse` containing the response of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`. + */ +extern NSString * const AFNetworkingOperationFailingURLResponseErrorKey; + /** Posted when an operation begins executing. */ diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 98a0343..e1c0a4b 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -42,7 +42,9 @@ typedef id AFBackgroundTaskIdentifier; static NSString * const kAFNetworkingLockName = @"com.alamofire.networking.operation.lock"; -NSString * const AFNetworkingErrorDomain = @"com.alamofire.networking.error"; +NSString * const AFNetworkingErrorDomain = @"AFNetworkingErrorDomain"; +NSString * const AFNetworkingOperationFailingURLRequestErrorKey = @"AFNetworkingOperationFailingURLRequestErrorKey"; +NSString * const AFNetworkingOperationFailingURLResponseErrorKey = @"AFNetworkingOperationFailingURLResponseErrorKey"; NSString * const AFNetworkingOperationDidStartNotification = @"com.alamofire.networking.operation.start"; NSString * const AFNetworkingOperationDidFinishNotification = @"com.alamofire.networking.operation.finish"; From ebe06c227d6deaaa027f51d40650dc7b111b6198 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 12:25:53 -0700 Subject: [PATCH 41/81] Changing error domain for failure to recognize file URL in multipart form data builder --- AFNetworking/AFHTTPClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 2257cb0..af82843 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -849,7 +849,7 @@ static inline NSString * AFMultipartFormFinalBoundary() { [userInfo setValue:fileURL forKey:NSURLErrorFailingURLErrorKey]; [userInfo setValue:NSLocalizedString(@"Expected URL to be a file URL", nil) forKey:NSLocalizedFailureReasonErrorKey]; if (error != NULL) { - *error = [[[NSError alloc] initWithDomain:AFNetworkingErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease]; + *error = [[[NSError alloc] initWithDomain:NSURLErrorDomain code:NSURLErrorBadURL userInfo:userInfo] autorelease]; } return NO; From 4f89cc650ec115e9c6c35be856f7563748ff0b96 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 14:15:35 -0700 Subject: [PATCH 42/81] Significant restructuring and editing of documentation, organizing notifications, functions, and constants into separate sections at the end of the class header --- AFNetworking/AFHTTPClient.h | 151 ++++++++++++++++-------- AFNetworking/AFHTTPRequestOperation.h | 15 ++- AFNetworking/AFURLConnectionOperation.h | 76 +++++++----- 3 files changed, 161 insertions(+), 81 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index e96592b..895850f 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -23,54 +23,6 @@ #import @class AFHTTPRequestOperation; -@protocol AFHTTPClientOperation; -@protocol AFMultipartFormData; - -/** - Posted when network reachability changes. - The notification object is an `NSNumber` object containing the boolean value for the current network reachability. - This notification contains no information in the `userInfo` dictionary. - - @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (Prefix.pch). - */ -#ifdef _SYSTEMCONFIGURATION_H -extern NSString * const AFNetworkingReachabilityDidChangeNotification; -#endif - -/** - Specifies network reachability of the client to its `baseURL` domain. - */ -#ifdef _SYSTEMCONFIGURATION_H -typedef enum { - AFNetworkReachabilityStatusUnknown = -1, - AFNetworkReachabilityStatusNotReachable = 0, - AFNetworkReachabilityStatusReachableViaWWAN = 1, - AFNetworkReachabilityStatusReachableViaWiFi = 2, -} AFNetworkReachabilityStatus; -#endif - -/** - Specifies the method used to encode parameters into request body. - */ -typedef enum { - AFFormURLParameterEncoding, - AFJSONParameterEncoding, - AFPropertyListParameterEncoding, -} AFHTTPClientParameterEncoding; - -/** - Returns a query string constructed by a set of parameters, using the specified encoding. - - @param parameters The parameters used to construct the query string - @param encoding The encoding to use in constructing the query string. If you are uncertain of the correct encoding, you should use UTF-8 (`NSUTF8StringEncoding`), which is the encoding designated by RFC 3986 as the correct encoding for use in URLs. - - @discussion Query strings are constructed by collecting each key-value pair, percent escaping a string representation of the key-value pair, and then joining the pairs with "&". - - If a query string pair has a an `NSArray` for its value, each member of the array will be represented in the format `field[]=value1&field[]value2`. Otherwise, the pair will be formatted as "field=value". String representations of both keys and values are derived using the `-description` method. The constructed query string does not include the ? character used to delimit the query component. - - @return A percent-escaped query string - */ -extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *parameters, NSStringEncoding encoding); /** `AFHTTPClient` captures the common patterns of communicating with an web application over HTTP. It encapsulates information like base URL, authorization credentials, and HTTP headers, and uses them to construct and manage the execution of HTTP request operations. @@ -110,6 +62,8 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete [NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo [NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/ [NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/ + + Also important to note is that a trailing slash will be added to any `baseURL` without one, which would otherwise cause unexpected behavior when constructing URLs using paths without a leading slash. ## NSCoding / NSCopying Conformance @@ -118,6 +72,25 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete - Archives and copies of HTTP clients will be initialized with an empty operation queue. - NSCoding cannot serialize / deserialize block properties, so an archive of an HTTP client will not include any reachability callback block that may be set. */ + +#ifdef _SYSTEMCONFIGURATION_H +typedef enum { + AFNetworkReachabilityStatusUnknown = -1, + AFNetworkReachabilityStatusNotReachable = 0, + AFNetworkReachabilityStatusReachableViaWWAN = 1, + AFNetworkReachabilityStatusReachableViaWiFi = 2, +} AFNetworkReachabilityStatus; +#endif + +typedef enum { + AFFormURLParameterEncoding, + AFJSONParameterEncoding, + AFPropertyListParameterEncoding, +} AFHTTPClientParameterEncoding; + +@protocol AFHTTPClientOperation; +@protocol AFMultipartFormData; + @interface AFHTTPClient : NSObject ///--------------------------------------- @@ -443,6 +416,87 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; @end +///---------------- +/// @name Constants +///---------------- + +/** + ### Network Reachability + + The following constants are provided by `AFHTTPClient` as possible network reachability statuses. + + enum { + AFNetworkReachabilityStatusUnknown, + AFNetworkReachabilityStatusNotReachable, + AFNetworkReachabilityStatusReachableViaWWAN, + AFNetworkReachabilityStatusReachableViaWiFi, + } + + `AFNetworkReachabilityStatusUnknown` + The `baseURL` host reachability is not known. + + `AFNetworkReachabilityStatusNotReachable` + The `baseURL` host cannot be reached. + + `AFNetworkReachabilityStatusReachableViaWWAN` + The `baseURL` host can be reached via a cellular connection, such as EDGE or GPRS. + + `AFNetworkReachabilityStatusReachableViaWiFi` + The `baseURL` host can be reached via a Wi-Fi connection. + + ### Parameter Encoding + + The following constants are provided by `AFHTTPClient` as possible methods for serializing parameters into query string or message body values. + + enum { + AFFormURLParameterEncoding, + AFJSONParameterEncoding, + AFPropertyListParameterEncoding, + } + + `AFFormURLParameterEncoding` + Parameters are encoded into field/key pairs in the URL query string for `GET` `HEAD` and `DELETE` requests, and in the message body otherwise. + + `AFJSONParameterEncoding` + Parameters are encoded into JSON in the message body. + + `AFPropertyListParameterEncoding` + Parameters are encoded into a property list in the message body. + */ + +///---------------- +/// @name Functions +///---------------- + +/** + Returns a query string constructed by a set of parameters, using the specified encoding. + + @param parameters The parameters used to construct the query string + @param encoding The encoding to use in constructing the query string. If you are uncertain of the correct encoding, you should use UTF-8 (`NSUTF8StringEncoding`), which is the encoding designated by RFC 3986 as the correct encoding for use in URLs. + + @discussion Query strings are constructed by collecting each key-value pair, percent escaping a string representation of the key-value pair, and then joining the pairs with "&". + + If a query string pair has a an `NSArray` for its value, each member of the array will be represented in the format `field[]=value1&field[]value2`. Otherwise, the pair will be formatted as "field=value". String representations of both keys and values are derived using the `-description` method. The constructed query string does not include the ? character used to delimit the query component. + + @return A percent-escaped query string + */ +extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *parameters, NSStringEncoding encoding); + +///-------------------- +/// @name Notifications +///-------------------- + +/** + Posted when network reachability changes. + The notification object is an `NSNumber` object containing the boolean value for the current network reachability. + This notification contains no information in the `userInfo` dictionary. + + @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (Prefix.pch). + */ +#ifdef _SYSTEMCONFIGURATION_H +extern NSString * const AFNetworkingReachabilityDidChangeNotification; +#endif + #pragma mark - /** @@ -506,4 +560,3 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete - (void)appendString:(NSString *)string; @end - diff --git a/AFNetworking/AFHTTPRequestOperation.h b/AFNetworking/AFHTTPRequestOperation.h index 608a6cb..af94ede 100644 --- a/AFNetworking/AFHTTPRequestOperation.h +++ b/AFNetworking/AFHTTPRequestOperation.h @@ -23,11 +23,6 @@ #import #import "AFURLConnectionOperation.h" -/** - Returns a set of MIME types detected in an HTTP `Accept` or `Content-Type` header. - */ -extern NSSet * AFContentTypesFromHTTPHeader(NSString *string); - /** `AFHTTPRequestOperation` is a subclass of `AFURLConnectionOperation` for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request. */ @@ -126,3 +121,13 @@ extern NSSet * AFContentTypesFromHTTPHeader(NSString *string); failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; @end + +///---------------- +/// @name Functions +///---------------- + +/** + Returns a set of MIME types detected in an HTTP `Accept` or `Content-Type` header. + */ +extern NSSet * AFContentTypesFromHTTPHeader(NSString *string); + diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index ad7ace8..5358ad5 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -22,33 +22,6 @@ #import -/** - Indicates an error occurred in AFNetworking. - - @discussion Error codes for AFNetworkingErrorDomain correspond to codes in NSURLErrorDomain. - */ -extern NSString * const AFNetworkingErrorDomain; - -/** - The corresponding value is an `NSURLRequest` containing the request of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`. - */ -extern NSString * const AFNetworkingOperationFailingURLRequestErrorKey; - -/** - The corresponding value is an `NSURLResponse` containing the response of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`. - */ -extern NSString * const AFNetworkingOperationFailingURLResponseErrorKey; - -/** - Posted when an operation begins executing. - */ -extern NSString * const AFNetworkingOperationDidStartNotification; - -/** - Posted when an operation finishes. - */ -extern NSString * const AFNetworkingOperationDidFinishNotification; - /** `AFURLConnectionOperation` is an `NSOperation` that implements NSURLConnection delegate methods. @@ -309,3 +282,52 @@ didReceiveResponse:(NSURLResponse *)response; willCacheResponse:(NSCachedURLResponse *)cachedResponse; @end + +///---------------- +/// @name Constants +///---------------- + +/** + ## User info dictionary keys + + These keys may exist in the user info dictionary, in addition to those defined for NSError. + + - `NSString * const AFNetworkingOperationFailingURLRequestErrorKey` + - `NSString * const AFNetworkingOperationFailingURLResponseErrorKey` + + ### Constants + + `AFNetworkingOperationFailingURLRequestErrorKey` + The corresponding value is an `NSURLRequest` containing the request of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`. + + `AFNetworkingOperationFailingURLResponseErrorKey` + The corresponding value is an `NSURLResponse` containing the response of the operation associated with an error. This key is only present in the `AFNetworkingErrorDomain`. + + ## Error Domains + + The following error domain is predefined. + + - `NSString * const AFNetworkingErrorDomain` + + ### Constants + + `AFNetworkingErrorDomain` + AFNetworking errors. Error codes for `AFNetworkingErrorDomain` correspond to codes in `NSURLErrorDomain`. + */ +extern NSString * const AFNetworkingErrorDomain; +extern NSString * const AFNetworkingOperationFailingURLRequestErrorKey; +extern NSString * const AFNetworkingOperationFailingURLResponseErrorKey; + +///-------------------- +/// @name Notifications +///-------------------- + +/** + Posted when an operation begins executing. + */ +extern NSString * const AFNetworkingOperationDidStartNotification; + +/** + Posted when an operation finishes. + */ +extern NSString * const AFNetworkingOperationDidFinishNotification; From 5166d5af85d7cb88a827938acbc09539a8b61d23 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Wed, 29 Aug 2012 14:16:27 -0700 Subject: [PATCH 43/81] Specifying Mac OS X in User-Agent (/thanks @tewha) --- AFNetworking/AFHTTPClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index af82843..92413e2 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -262,7 +262,7 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]]; #elif __MAC_OS_X_VERSION_MIN_REQUIRED - [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]]; + [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]]; #endif #ifdef _SYSTEMCONFIGURATION_H From e3307924110bfd54e342cf600c6fb48a0a5bd44b Mon Sep 17 00:00:00 2001 From: Tony Million Date: Thu, 30 Aug 2012 21:51:39 +0100 Subject: [PATCH 44/81] hasAcceptableStatusCode will return true after a network failure --- AFNetworking/AFHTTPRequestOperation.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 26b0eb0..31efc4d 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -173,7 +173,7 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { } - (BOOL)hasAcceptableStatusCode { - NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; + NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 0; return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:statusCode]; } From cdbae5a9fbb6d6cec795d981b055878f340dbd0b Mon Sep 17 00:00:00 2001 From: Tony Million Date: Fri, 31 Aug 2012 09:27:43 +0100 Subject: [PATCH 45/81] tests self.response before blindy returning 200 in hasAcceptableStatusCode if self.response is nil then network failure is assumed --- AFNetworking/AFHTTPRequestOperation.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 31efc4d..2539d3a 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -173,7 +173,12 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { } - (BOOL)hasAcceptableStatusCode { - NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 0; + if(!self.response) { + // no response means network failure or such + return NO; + } + + NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:statusCode]; } From e445903901084566ab1953dda17f042ea4ec5bca Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 31 Aug 2012 08:41:57 -0700 Subject: [PATCH 46/81] Adding early return for hasAcceptableContentType --- AFNetworking/AFHTTPRequestOperation.m | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 2539d3a..940a85f 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -173,16 +173,19 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { } - (BOOL)hasAcceptableStatusCode { - if(!self.response) { - // no response means network failure or such + if (!self.response) { return NO; } - + NSUInteger statusCode = ([self.response isKindOfClass:[NSHTTPURLResponse class]]) ? (NSUInteger)[self.response statusCode] : 200; return ![[self class] acceptableStatusCodes] || [[[self class] acceptableStatusCodes] containsIndex:statusCode]; } - (BOOL)hasAcceptableContentType { + if (!self.response) { + return NO; + } + return ![[self class] acceptableContentTypes] || [[[self class] acceptableContentTypes] containsObject:[self.response MIMEType]]; } From 1a23b987789033ca5b0349694032283d1b786d78 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 31 Aug 2012 08:42:53 -0700 Subject: [PATCH 47/81] Using more idiomatic ?: for AFHTTPRequestOperation -setCompletionBlockWithSuccess:failure: --- AFNetworking/AFHTTPRequestOperation.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 940a85f..9d09e1c 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -227,13 +227,13 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { if (self.error) { if (failure) { - dispatch_async(self.failureCallbackQueue ? self.failureCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.failureCallbackQueue ?: dispatch_get_main_queue(), ^{ failure(self, self.error); }); } } else { if (success) { - dispatch_async(self.successCallbackQueue ? self.successCallbackQueue : dispatch_get_main_queue(), ^{ + dispatch_async(self.successCallbackQueue ?: dispatch_get_main_queue(), ^{ success(self, self.responseData); }); } From ec0240f6e4d72498cb8343f55ca04e4852512c2e Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 31 Aug 2012 09:04:54 -0700 Subject: [PATCH 48/81] [Issue #489] Adding userInfo dictionary with current status in reachability changes --- AFNetworking/AFHTTPClient.h | 12 ++++++++++-- AFNetworking/AFHTTPClient.m | 7 ++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 895850f..76a4a92 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -444,6 +444,14 @@ typedef enum { `AFNetworkReachabilityStatusReachableViaWiFi` The `baseURL` host can be reached via a Wi-Fi connection. + ### Keys for Notification UserInfo Dictionary + + Strings that are used as keys in a userinfo dictionary in a network reachability status change notification. + + `AFNetworkingReachabilityNotificationStatusItem` + A key in the userInfo dictionary in a `AFNetworkingReachabilityDidChangeNotification` notification. + The corresponding value is an `NSNumber` object representing the `AFNetworkReachabilityStatus` value for the current reachability status. + ### Parameter Encoding The following constants are provided by `AFHTTPClient` as possible methods for serializing parameters into query string or message body values. @@ -488,13 +496,13 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete /** Posted when network reachability changes. - The notification object is an `NSNumber` object containing the boolean value for the current network reachability. - This notification contains no information in the `userInfo` dictionary. + This notification assigns no notification object. The `userInfo` dictionary contains an `NSNumber` object under the `AFNetworkingReachabilityNotificationStatusItem` key, representing the `AFNetworkReachabilityStatus` value for the current network reachability. @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (Prefix.pch). */ #ifdef _SYSTEMCONFIGURATION_H extern NSString * const AFNetworkingReachabilityDidChangeNotification; +extern NSString * const AFNetworkingReachabilityNotificationStatusItem; #endif #pragma mark - diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 92413e2..04c99ed 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -41,8 +41,6 @@ #import #endif -NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change"; - @interface AFMultipartFormData : NSObject - (id)initWithURLRequest:(NSMutableURLRequest *)request @@ -55,6 +53,9 @@ NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire #pragma mark - #ifdef _SYSTEMCONFIGURATION_H +NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change"; +NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem"; + typedef SCNetworkReachabilityRef AFNetworkReachabilityRef; typedef void (^AFNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status); #else @@ -332,7 +333,7 @@ static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused targ block(status); } - [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingReachabilityDidChangeNotification object:[NSNumber numberWithInt:status]]; + [[NSNotificationCenter defaultCenter] postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:[NSDictionary dictionaryWithObject:[NSNumber numberWithInteger:status] forKey:AFNetworkingReachabilityNotificationStatusItem]]; } static const void * AFNetworkReachabilityRetainCallback(const void *info) { From 26b5a3b533d9a4661b71054b877350d00dc69cb8 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 31 Aug 2012 09:09:52 -0700 Subject: [PATCH 49/81] Fixing name of path param in -cancelAllHTTPOperationsWithMethod:path: documentation --- AFNetworking/AFHTTPClient.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 76a4a92..5af49b3 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -304,7 +304,7 @@ typedef enum { Cancels all operations in the HTTP client's operation queue whose URLs match the specified HTTP method and path. @param method The HTTP method to match for the cancelled requests, such as `GET`, `POST`, `PUT`, or `DELETE`. If `nil`, all request operations with URLs matching the path will be cancelled. - @param url The path to match for the cancelled requests. + @param path The path to match for the cancelled requests. */ - (void)cancelAllHTTPOperationsWithMethod:(NSString *)method path:(NSString *)path; From edb0830128712517df2461b8567860a9d23abfc6 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 31 Aug 2012 09:13:18 -0700 Subject: [PATCH 50/81] Removing references to AFHTTPClientOperation protocol in documentation --- AFNetworking/AFHTTPClient.h | 9 +++------ AFNetworking/AFImageRequestOperation.m | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index 5af49b3..a20ce8b 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -29,7 +29,7 @@ ## Automatic Content Parsing - Instances of `AFHTTPClient` may specify which types of requests it expects and should handle by registering HTTP operation classes for automatic parsing. Registered classes will determine whether they can handle a particular request, and then construct a request operation accordingly in `enqueueHTTPRequestOperationWithRequest:success:failure`. See `AFHTTPClientOperation` for further details. + Instances of `AFHTTPClient` may specify which types of requests it expects and should handle by registering HTTP operation classes for automatic parsing. Registered classes will determine whether they can handle a particular request, and then construct a request operation accordingly in `enqueueHTTPRequestOperationWithRequest:success:failure`. ## Subclassing Notes @@ -88,7 +88,6 @@ typedef enum { AFPropertyListParameterEncoding, } AFHTTPClientParameterEncoding; -@protocol AFHTTPClientOperation; @protocol AFMultipartFormData; @interface AFHTTPClient : NSObject @@ -174,20 +173,18 @@ typedef enum { /** Attempts to register a subclass of `AFHTTPRequestOperation`, adding it to a chain to automatically generate request operations from a URL request. - @param The subclass of `AFHTTPRequestOperation` to register + @param operationClass The subclass of `AFHTTPRequestOperation` to register @return `YES` if the registration is successful, `NO` otherwise. The only failure condition is if `operationClass` is not a subclass of `AFHTTPRequestOperation`. @discussion When `enqueueHTTPRequestOperationWithRequest:success:failure` is invoked, each registered class is consulted in turn to see if it can handle the specific request. The first class to return `YES` when sent a `canProcessRequest:` message is used to create an operation using `initWithURLRequest:` and do `setCompletionBlockWithSuccess:failure:`. There is no guarantee that all registered classes will be consulted. Classes are consulted in the reverse order of their registration. Attempting to register an already-registered class will move it to the top of the list. - - @see `AFHTTPClientOperation` */ - (BOOL)registerHTTPOperationClass:(Class)operationClass; /** Unregisters the specified subclass of `AFHTTPRequestOperation`. - @param The class conforming to the `AFHTTPClientOperation` protocol to unregister + @param operationClass The subclass of `AFHTTPRequestOperation` to register @discussion After this method is invoked, `operationClass` is no longer consulted when `requestWithMethod:path:parameters` is invoked. */ diff --git a/AFNetworking/AFImageRequestOperation.m b/AFNetworking/AFImageRequestOperation.m index fbd1e22..a4ca899 100644 --- a/AFNetworking/AFImageRequestOperation.m +++ b/AFNetworking/AFImageRequestOperation.m @@ -186,7 +186,7 @@ static dispatch_queue_t image_request_operation_processing_queue() { } #endif -#pragma mark - AFHTTPClientOperation +#pragma mark - AFHTTPRequestOperation + (NSSet *)acceptableContentTypes { return [NSSet setWithObjects:@"image/tiff", @"image/jpeg", @"image/gif", @"image/png", @"image/ico", @"image/x-icon", @"image/bmp", @"image/x-bmp", @"image/x-xbitmap", @"image/x-win-bitmap", nil]; From 5ddd070607d801f305fbfe6550e81d0b47a8881c Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 31 Aug 2012 09:53:55 -0700 Subject: [PATCH 51/81] Fixing appledoc compliation errors in documentation Assorted copy edits and reformatting to documentation --- AFNetworking/AFHTTPClient.h | 67 +++++++++++++------------ AFNetworking/AFImageRequestOperation.h | 6 +-- AFNetworking/AFURLConnectionOperation.h | 10 +--- 3 files changed, 38 insertions(+), 45 deletions(-) diff --git a/AFNetworking/AFHTTPClient.h b/AFNetworking/AFHTTPClient.h index a20ce8b..97d089b 100644 --- a/AFNetworking/AFHTTPClient.h +++ b/AFNetworking/AFHTTPClient.h @@ -46,23 +46,23 @@ By default, `AFHTTPClient` sets the following HTTP headers: - `Accept-Encoding: gzip` - - `Accept-Language: ([NSLocale preferredLanguages]), en-us;q=0.8` + - `Accept-Language: (comma-delimited preferred languages), en-us;q=0.8` - `User-Agent: (generated user agent)` You can override these HTTP headers or define new ones using `setDefaultHeader:value:`. ## URL Construction Using Relative Paths - Both `requestWithMethod:path:parameters` and `multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` construct URLs from the path relative to the `baseURL`, using `NSURL +URLWithString:relativeToURL:`. Below are a few examples of how `baseURL` and relative paths interact: - - NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"]; - [NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo - [NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz - [NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo - [NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo - [NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/ - [NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/ + Both `-requestWithMethod:path:parameters:` and `-multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` construct URLs from the path relative to the `-baseURL`, using `NSURL +URLWithString:relativeToURL:`. Below are a few examples of how `baseURL` and relative paths interact: + NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"]; + [NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo + [NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz + [NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo + [NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo + [NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/ + [NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/ + Also important to note is that a trailing slash will be added to any `baseURL` without one, which would otherwise cause unexpected behavior when constructing URLs using paths without a leading slash. ## NSCoding / NSCopying Conformance @@ -121,7 +121,7 @@ typedef enum { /** The reachability status from the device to the current `baseURL` of the `AFHTTPClient`. - @warning This property requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (Prefix.pch). + @warning This property requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (`Prefix.pch`). */ #ifdef _SYSTEMCONFIGURATION_H @property (readonly, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus; @@ -160,7 +160,7 @@ typedef enum { @param block A block object to be executed when the network availability of the `baseURL` host changes.. This block has no return value and takes a single argument which represents the various reachability states from the device to the `baseURL`. - @warning This method requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (Prefix.pch). + @warning This method requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (`Prefix.pch`). */ #ifdef _SYSTEMCONFIGURATION_H - (void)setReachabilityStatusChangeBlock:(void (^)(AFNetworkReachabilityStatus status))block; @@ -182,11 +182,9 @@ typedef enum { - (BOOL)registerHTTPOperationClass:(Class)operationClass; /** - Unregisters the specified subclass of `AFHTTPRequestOperation`. - - @param operationClass The subclass of `AFHTTPRequestOperation` to register - - @discussion After this method is invoked, `operationClass` is no longer consulted when `requestWithMethod:path:parameters` is invoked. + Unregisters the specified subclass of `AFHTTPRequestOperation` from the chain of classes consulted when `-requestWithMethod:path:parameters` is called. + + @param operationClass The subclass of `AFHTTPRequestOperation` to register */ - (void)unregisterHTTPOperationClass:(Class)operationClass; @@ -345,7 +343,7 @@ typedef enum { @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. - @see HTTPRequestOperationWithRequest:success:failure + @see -HTTPRequestOperationWithRequest:success:failure: */ - (void)getPath:(NSString *)path parameters:(NSDictionary *)parameters @@ -360,7 +358,7 @@ typedef enum { @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. - @see HTTPRequestOperationWithRequest:success:failure + @see -HTTPRequestOperationWithRequest:success:failure: */ - (void)postPath:(NSString *)path parameters:(NSDictionary *)parameters @@ -375,7 +373,7 @@ typedef enum { @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. - @see HTTPRequestOperationWithRequest:success:failure + @see -HTTPRequestOperationWithRequest:success:failure: */ - (void)putPath:(NSString *)path parameters:(NSDictionary *)parameters @@ -390,7 +388,7 @@ typedef enum { @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. - @see HTTPRequestOperationWithRequest:success:failure + @see -HTTPRequestOperationWithRequest:success:failure: */ - (void)deletePath:(NSString *)path parameters:(NSDictionary *)parameters @@ -405,7 +403,7 @@ typedef enum { @param success A block object to be executed when the request operation finishes successfully. This block has no return value and takes two arguments: the created request operation and the object created from the response data of request. @param failure A block object to be executed when the request operation finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes two arguments:, the created request operation and the `NSError` object describing the network or parsing error that occurred. - @see HTTPRequestOperationWithRequest:success:failure + @see -HTTPRequestOperationWithRequest:success:failure: */ - (void)patchPath:(NSString *)path parameters:(NSDictionary *)parameters @@ -443,7 +441,7 @@ typedef enum { ### Keys for Notification UserInfo Dictionary - Strings that are used as keys in a userinfo dictionary in a network reachability status change notification. + Strings that are used as keys in a `userInfo` dictionary in a network reachability status change notification. `AFNetworkingReachabilityNotificationStatusItem` A key in the userInfo dictionary in a `AFNetworkingReachabilityDidChangeNotification` notification. @@ -495,7 +493,7 @@ extern NSString * AFQueryStringFromParametersWithEncoding(NSDictionary *paramete Posted when network reachability changes. This notification assigns no notification object. The `userInfo` dictionary contains an `NSNumber` object under the `AFNetworkingReachabilityNotificationStatusItem` key, representing the `AFNetworkReachabilityStatus` value for the current network reachability. - @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (Prefix.pch). + @warning In order for network reachability to be monitored, include the `SystemConfiguration` framework in the active target's "Link Binary With Library" build phase, and add `#import ` to the header prefix of the project (`Prefix.pch`). */ #ifdef _SYSTEMCONFIGURATION_H extern NSString * const AFNetworkingReachabilityDidChangeNotification; @@ -505,9 +503,7 @@ extern NSString * const AFNetworkingReachabilityNotificationStatusItem; #pragma mark - /** - The `AFMultipartFormData` protocol defines the methods supported by the parameter in the block argument of `multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:`. - - @see `AFHTTPClient -multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` + The `AFMultipartFormData` protocol defines the methods supported by the parameter in the block argument of `-multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:`. */ @protocol AFMultipartFormData @@ -517,7 +513,8 @@ extern NSString * const AFNetworkingReachabilityNotificationStatusItem; @param headers The HTTP headers to be appended to the form data. @param body The data to be encoded and appended to the form data. */ -- (void)appendPartWithHeaders:(NSDictionary *)headers body:(NSData *)body; +- (void)appendPartWithHeaders:(NSDictionary *)headers + body:(NSData *)body; /** Appends the HTTP headers `Content-Disposition: form-data; name=#{name}"`, followed by the encoded data and the multipart form boundary. @@ -525,17 +522,21 @@ extern NSString * const AFNetworkingReachabilityNotificationStatusItem; @param data The data to be encoded and appended to the form data. @param name The name to be associated with the specified data. This parameter must not be `nil`. */ -- (void)appendPartWithFormData:(NSData *)data name:(NSString *)name; +- (void)appendPartWithFormData:(NSData *)data + name:(NSString *)name; /** Appends the HTTP header `Content-Disposition: file; filename=#{filename}; name=#{name}"` and `Content-Type: #{mimeType}`, followed by the encoded file data and the multipart form boundary. @param data The data to be encoded and appended to the form data. @param name The name to be associated with the specified data. This parameter must not be `nil`. + @param fileName The filename to be associated with the specified data. This parameter must not be `nil`. @param mimeType The MIME type of the specified data. (For example, the MIME type for a JPEG image is image/jpeg.) For a list of valid MIME types, see http://www.iana.org/assignments/media-types/. This parameter must not be `nil`. - @param filename The filename to be associated with the specified data. This parameter must not be `nil`. */ -- (void)appendPartWithFileData:(NSData *)data name:(NSString *)name fileName:(NSString *)fileName mimeType:(NSString *)mimeType; +- (void)appendPartWithFileData:(NSData *)data + name:(NSString *)name + fileName:(NSString *)fileName + mimeType:(NSString *)mimeType; /** Appends the HTTP header `Content-Disposition: file; filename=#{generated filename}; name=#{name}"` and `Content-Type: #{generated mimeType}`, followed by the encoded file data and the multipart form boundary. @@ -548,7 +549,9 @@ extern NSString * const AFNetworkingReachabilityNotificationStatusItem; @discussion The filename and MIME type for this data in the form will be automatically generated, using `NSURLResponse` `-suggestedFilename` and `-MIMEType`, respectively. */ -- (BOOL)appendPartWithFileURL:(NSURL *)fileURL name:(NSString *)name error:(NSError **)error; +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL + name:(NSString *)name + error:(NSError **)error; /** Appends encoded data to the form data. diff --git a/AFNetworking/AFImageRequestOperation.h b/AFNetworking/AFImageRequestOperation.h index f6de586..3162bb2 100644 --- a/AFNetworking/AFImageRequestOperation.h +++ b/AFNetworking/AFImageRequestOperation.h @@ -62,15 +62,11 @@ #if __IPHONE_OS_VERSION_MIN_REQUIRED /** - The scale factor used when interpreting the image data to construct `responseImage`. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of `[[UIScreen mainScreen] scale]` by default, which automatically scales images for retina displays, for instance. + The scale factor used when interpreting the image data to construct `responseImage`. Specifying a scale factor of 1.0 results in an image whose size matches the pixel-based dimensions of the image. Applying a different scale factor changes the size of the image as reported by the size property. This is set to the value of scale of the main screen by default, which automatically scales images for retina displays, for instance. */ @property (nonatomic, assign) CGFloat imageScale; #endif -/** - An image constructed from the response data. If an error occurs during the request, `nil` will be returned, and the `error` property will be set to the error. - */ - /** Creates and returns an `AFImageRequestOperation` object and sets the specified success callback. diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index 5358ad5..5936797 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -54,7 +54,7 @@ The built-in `completionBlock` provided by `NSOperation` allows for custom behavior to be executed after the request finishes. It is a common pattern for class constructors in subclasses to take callback block parameters, and execute them conditionally in the body of its `completionBlock`. Make sure to handle cancelled operations appropriately when setting a `completionBlock` (e.g. returning early before parsing response data). See the implementation of any of the `AFHTTPRequestOperation` subclasses for an example of this. - @warning Subclasses are strongly discouraged from overriding `setCompletionBlock:`, as `AFURLConnectionOperation`'s implementation includes a workaround to mitigate retain cycles, and what Apple rather ominously refers to as "The Deallocation Problem" (See http://developer.apple.com/library/ios/technotes/tn2109/_index.html#//apple_ref/doc/uid/DTS40010274-CH1-SUBSECTION11) + Subclasses are strongly discouraged from overriding `setCompletionBlock:`, as `AFURLConnectionOperation`'s implementation includes a workaround to mitigate retain cycles, and what Apple rather ominously refers to as ["The Deallocation Problem"](http://developer.apple.com/library/ios/#technotes/tn2109/). ## NSCoding & NSCopying Conformance @@ -69,7 +69,7 @@ - `-copy` and `-copyWithZone:` return a new operation with the `NSURLRequest` of the original. So rather than an exact copy of the operation at that particular instant, the copying mechanism returns a completely new instance, which can be useful for retrying operations. - A copy of an operation will not include the `outputStream` of the original. - - Operation copies do not include `completionBlock`. `completionBlock` often strongly captures a reference to `self`, which, perhaps surprisingly, would otherwise point to the _original_ operation when copied. + - Operation copies do not include `completionBlock`. `completionBlock` often strongly captures a reference to `self`, which, perhaps surprisingly, would otherwise point to the _original_ operation when copied. */ @interface AFURLConnectionOperation : NSOperation @@ -194,10 +194,6 @@ Sets a callback to be called when an undetermined number of bytes have been uploaded to the server. @param block A block object to be called when an undetermined number of bytes have been uploaded to the server. This block has no return value and takes three arguments: the number of bytes written since the last time the upload progress block was called, the total bytes written, and the total bytes expected to be written during the request, as initially determined by the length of the HTTP body. This block may be called multiple times, and will execute on the main thread. - - @discussion This block is called on the main thread. - - @see setDownloadProgressBlock */ - (void)setUploadProgressBlock:(void (^)(NSUInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite))block; @@ -205,8 +201,6 @@ Sets a callback to be called when an undetermined number of bytes have been downloaded from the server. @param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes three arguments: the number of bytes read since the last time the download progress block was called, the total bytes read, and the total bytes expected to be read during the request, as initially determined by the expected content size of the `NSHTTPURLResponse` object. This block may be called multiple times, and will execute on the main thread. - - @see setUploadProgressBlock */ - (void)setDownloadProgressBlock:(void (^)(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead))block; From 70dff01807c1ff7f8f72575d7c43269ae1c07346 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 31 Aug 2012 16:57:04 -0700 Subject: [PATCH 52/81] Using dispatch_once pattern for initializing UIImageView request operation queue singleton Initializing operation queue with NSOperationQueueDefaultMaxConcurrentOperationCount --- AFNetworking/UIImageView+AFNetworking.m | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/AFNetworking/UIImageView+AFNetworking.m b/AFNetworking/UIImageView+AFNetworking.m index 6de959f..70bd401 100644 --- a/AFNetworking/UIImageView+AFNetworking.m +++ b/AFNetworking/UIImageView+AFNetworking.m @@ -59,10 +59,11 @@ static char kAFImageRequestOperationObjectKey; + (NSOperationQueue *)af_sharedImageRequestOperationQueue { static NSOperationQueue *_af_imageRequestOperationQueue = nil; - if (!_af_imageRequestOperationQueue) { + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ _af_imageRequestOperationQueue = [[NSOperationQueue alloc] init]; - [_af_imageRequestOperationQueue setMaxConcurrentOperationCount:8]; - } + [_af_imageRequestOperationQueue setMaxConcurrentOperationCount:NSOperationQueueDefaultMaxConcurrentOperationCount]; + }); return _af_imageRequestOperationQueue; } From b614dee5bb938abbfbf6fd2dda8d67b812dabc42 Mon Sep 17 00:00:00 2001 From: Mike Lewis Date: Fri, 31 Aug 2012 23:29:11 -0700 Subject: [PATCH 53/81] Removing setting Accept-Encoding by default. NSURLConnection will set this to the supported formats which is a superset of gzip. (at least in 5.1 it set deflate as well) --- AFNetworking/AFHTTPClient.m | 3 --- 1 file changed, 3 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 04c99ed..d5af72c 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -251,9 +251,6 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { self.registeredHTTPOperationClassNames = [NSMutableArray array]; self.defaultHeaders = [NSMutableDictionary dictionary]; - - // Accept-Encoding HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3 - [self setDefaultHeader:@"Accept-Encoding" value:@"gzip"]; // Accept-Language HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 NSString *preferredLanguageCodes = [[NSLocale preferredLanguages] componentsJoinedByString:@", "]; From 858c716c16c479cc8e142a719c90fad0316eaf8f Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 3 Sep 2012 11:11:24 -0700 Subject: [PATCH 54/81] Re-indenting AFHTTPClient.m --- AFNetworking/AFHTTPClient.m | 110 ++++++++++++++++++------------------ 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 04c99ed..b671c9a 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -1,17 +1,17 @@ // AFHTTPClient.m // // Copyright (c) 2011 Gowalla (http://gowalla.com/) -// +// // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: -// +// // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. -// +// // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE @@ -43,7 +43,7 @@ @interface AFMultipartFormData : NSObject -- (id)initWithURLRequest:(NSMutableURLRequest *)request +- (id)initWithURLRequest:(NSMutableURLRequest *)request stringEncoding:(NSStringEncoding)encoding; - (NSMutableURLRequest *)requestByFinalizingMultipartFormData; @@ -77,7 +77,7 @@ static NSString * AFBase64EncodedStringFromString(NSString *string) { for (NSUInteger j = i; j < (i + 3); j++) { value <<= 8; if (j < length) { - value |= (0xFF & input[j]); + value |= (0xFF & input[j]); } } @@ -96,7 +96,7 @@ static NSString * AFBase64EncodedStringFromString(NSString *string) { NSString * AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(NSString *string, NSStringEncoding encoding) { // Escape characters that are legal in URIs, but have unintentional semantic significance when used in a query string parameter static NSString * const kAFLegalCharactersToBeEscaped = @":/.?&=;+!@$()~"; - + return [(NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)string, NULL, (CFStringRef)kAFLegalCharactersToBeEscaped, CFStringConvertNSStringEncodingToEncoding(encoding)) autorelease]; } @@ -111,7 +111,7 @@ NSString * AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(NSString @end -@implementation AFQueryStringPair +@implementation AFQueryStringPair @synthesize field = _field; @synthesize value = _value; @@ -170,7 +170,7 @@ NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value) { }]; } else { [mutableQueryStringComponents addObject:[[[AFQueryStringPair alloc] initWithField:key value:value] autorelease]]; - } + } return mutableQueryStringComponents; } @@ -250,22 +250,22 @@ static NSString * AFPropertyListStringFromParameters(NSDictionary *parameters) { self.registeredHTTPOperationClassNames = [NSMutableArray array]; - self.defaultHeaders = [NSMutableDictionary dictionary]; + self.defaultHeaders = [NSMutableDictionary dictionary]; - // Accept-Encoding HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3 - [self setDefaultHeader:@"Accept-Encoding" value:@"gzip"]; + // Accept-Encoding HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.3 + [self setDefaultHeader:@"Accept-Encoding" value:@"gzip"]; - // Accept-Language HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 - NSString *preferredLanguageCodes = [[NSLocale preferredLanguages] componentsJoinedByString:@", "]; - [self setDefaultHeader:@"Accept-Language" value:[NSString stringWithFormat:@"%@, en-us;q=0.8", preferredLanguageCodes]]; - + // Accept-Language HTTP Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.4 + NSString *preferredLanguageCodes = [[NSLocale preferredLanguages] componentsJoinedByString:@", "]; + [self setDefaultHeader:@"Accept-Language" value:[NSString stringWithFormat:@"%@, en-us;q=0.8", preferredLanguageCodes]]; + #if __IPHONE_OS_VERSION_MIN_REQUIRED // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle(), kCFBundleVersionKey) ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], ([[UIScreen mainScreen] respondsToSelector:@selector(scale)] ? [[UIScreen mainScreen] scale] : 1.0f)]]; #elif __MAC_OS_X_VERSION_MIN_REQUIRED [self setDefaultHeader:@"User-Agent" value:[NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleExecutableKey] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleIdentifierKey], [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"] ?: [[[NSBundle mainBundle] infoDictionary] objectForKey:(NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]]; #endif - + #ifdef _SYSTEMCONFIGURATION_H self.networkReachabilityStatus = AFNetworkReachabilityStatusUnknown; [self startMonitoringNetworkReachability]; @@ -326,7 +326,7 @@ static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetwork return status; } -static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) { +static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) { AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags); AFNetworkReachabilityStatusBlock block = (AFNetworkReachabilityStatusBlock)info; if (block) { @@ -432,20 +432,20 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { #pragma mark - -- (NSMutableURLRequest *)requestWithMethod:(NSString *)method - path:(NSString *)path - parameters:(NSDictionary *)parameters -{ +- (NSMutableURLRequest *)requestWithMethod:(NSString *)method + path:(NSString *)path + parameters:(NSDictionary *)parameters +{ NSURL *url = [NSURL URLWithString:path relativeToURL:self.baseURL]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] initWithURL:url] autorelease]; [request setHTTPMethod:method]; [request setAllHTTPHeaderFields:self.defaultHeaders]; - + if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"]) { [request setHTTPShouldUsePipelining:YES]; } - if (parameters) { + if (parameters) { if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"] || [method isEqualToString:@"DELETE"]) { url = [NSURL URLWithString:[[url absoluteString] stringByAppendingFormat:[path rangeOfString:@"?"].location == NSNotFound ? @"?%@" : @"&%@", AFQueryStringFromParametersWithEncoding(parameters, self.stringEncoding)]]; [request setURL:url]; @@ -501,7 +501,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { return [formData requestByFinalizingMultipartFormData]; } -- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest +- (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { @@ -542,8 +542,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { } } -- (void)enqueueBatchOfHTTPRequestOperationsWithRequests:(NSArray *)requests - progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock +- (void)enqueueBatchOfHTTPRequestOperationsWithRequests:(NSArray *)requests + progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock completionBlock:(void (^)(NSArray *operations))completionBlock { NSMutableArray *mutableOperations = [NSMutableArray array]; @@ -555,8 +555,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { [self enqueueBatchOfHTTPRequestOperations:mutableOperations progressBlock:progressBlock completionBlock:completionBlock]; } -- (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations - progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock +- (void)enqueueBatchOfHTTPRequestOperations:(NSArray *)operations + progressBlock:(void (^)(NSUInteger numberOfFinishedOperations, NSUInteger totalNumberOfOperations))progressBlock completionBlock:(void (^)(NSArray *operations))completionBlock { __block dispatch_group_t dispatchGroup = dispatch_group_create(); @@ -568,7 +568,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { }); dispatch_release(dispatchGroup); }]; - + for (AFHTTPRequestOperation *operation in operations) { AFCompletionBlock originalCompletionBlock = [[operation.completionBlock copy] autorelease]; operation.completionBlock = ^{ @@ -603,8 +603,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { #pragma mark - -- (void)getPath:(NSString *)path - parameters:(NSDictionary *)parameters +- (void)getPath:(NSString *)path + parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { @@ -613,8 +613,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { [self enqueueHTTPRequestOperation:operation]; } -- (void)postPath:(NSString *)path - parameters:(NSDictionary *)parameters +- (void)postPath:(NSString *)path + parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { @@ -623,8 +623,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { [self enqueueHTTPRequestOperation:operation]; } -- (void)putPath:(NSString *)path - parameters:(NSDictionary *)parameters +- (void)putPath:(NSString *)path + parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { @@ -633,8 +633,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { [self enqueueHTTPRequestOperation:operation]; } -- (void)deletePath:(NSString *)path - parameters:(NSDictionary *)parameters +- (void)deletePath:(NSString *)path + parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { @@ -643,8 +643,8 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { [self enqueueHTTPRequestOperation:operation]; } -- (void)patchPath:(NSString *)path - parameters:(NSDictionary *)parameters +- (void)patchPath:(NSString *)path + parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { @@ -735,7 +735,7 @@ static inline NSString * AFMultipartFormFinalBoundary() { @property (readwrite, nonatomic, retain) NSMutableURLRequest *request; @property (readwrite, nonatomic, assign) NSStringEncoding stringEncoding; @property (readwrite, nonatomic, retain) NSOutputStream *outputStream; -@property (readwrite, nonatomic, copy) NSString *temporaryFilePath; +@property (readwrite, nonatomic, copy) NSString *temporaryFilePath; @end @implementation AFMultipartFormData @@ -744,8 +744,8 @@ static inline NSString * AFMultipartFormFinalBoundary() { @synthesize outputStream = _outputStream; @synthesize temporaryFilePath = _temporaryFilePath; -- (id)initWithURLRequest:(NSMutableURLRequest *)request - stringEncoding:(NSStringEncoding)encoding +- (id)initWithURLRequest:(NSMutableURLRequest *)request + stringEncoding:(NSStringEncoding)encoding { self = [super init]; if (!self) { @@ -785,7 +785,7 @@ static inline NSString * AFMultipartFormFinalBoundary() { return self.request; } - + [self appendData:[AFMultipartFormFinalBoundary() dataUsingEncoding:self.stringEncoding]]; [self.request setValue:[NSString stringWithFormat:@"multipart/form-data; boundary=%@", kAFMultipartFormBoundary] forHTTPHeaderField:@"Content-Type"]; @@ -807,8 +807,8 @@ static inline NSString * AFMultipartFormFinalBoundary() { } } -- (void)appendPartWithHeaders:(NSDictionary *)headers - body:(NSData *)body +- (void)appendPartWithHeaders:(NSDictionary *)headers + body:(NSData *)body { [self appendBoundary]; @@ -820,8 +820,8 @@ static inline NSString * AFMultipartFormFinalBoundary() { [self appendData:body]; } -- (void)appendPartWithFormData:(NSData *)data - name:(NSString *)name +- (void)appendPartWithFormData:(NSData *)data + name:(NSString *)name { NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary]; [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"", name] forKey:@"Content-Disposition"]; @@ -829,11 +829,11 @@ static inline NSString * AFMultipartFormFinalBoundary() { [self appendPartWithHeaders:mutableHeaders body:data]; } -- (void)appendPartWithFileData:(NSData *)data - name:(NSString *)name - fileName:(NSString *)fileName +- (void)appendPartWithFileData:(NSData *)data + name:(NSString *)name + fileName:(NSString *)fileName mimeType:(NSString *)mimeType -{ +{ NSMutableDictionary *mutableHeaders = [NSMutableDictionary dictionary]; [mutableHeaders setValue:[NSString stringWithFormat:@"form-data; name=\"%@\"; filename=\"%@\"", name, fileName] forKey:@"Content-Disposition"]; [mutableHeaders setValue:mimeType forKey:@"Content-Type"]; @@ -841,9 +841,9 @@ static inline NSString * AFMultipartFormFinalBoundary() { [self appendPartWithHeaders:mutableHeaders body:data]; } -- (BOOL)appendPartWithFileURL:(NSURL *)fileURL - name:(NSString *)name - error:(NSError **)error +- (BOOL)appendPartWithFileURL:(NSURL *)fileURL + name:(NSString *)name + error:(NSError **)error { if (![fileURL isFileURL]) { NSMutableDictionary *userInfo = [NSMutableDictionary dictionary]; @@ -879,7 +879,7 @@ static inline NSString * AFMultipartFormFinalBoundary() { if ([data length] == 0) { return; } - + if ([self.outputStream hasSpaceAvailable]) { const uint8_t *dataBuffer = (uint8_t *) [data bytes]; [self.outputStream write:&dataBuffer[0] maxLength:[data length]]; From e1dafd15ecad6acad6c2fc76f40e1bb4549bbe27 Mon Sep 17 00:00:00 2001 From: Stephan Diederich Date: Tue, 4 Sep 2012 19:24:03 +0200 Subject: [PATCH 55/81] fix warning Xcode warns about a missing prototype which can be fixed by making the (private) method static --- AFNetworking/AFHTTPClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index d5af72c..0596022 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -93,7 +93,7 @@ static NSString * AFBase64EncodedStringFromString(NSString *string) { return [[[NSString alloc] initWithData:mutableData encoding:NSASCIIStringEncoding] autorelease]; } -NSString * AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(NSString *string, NSStringEncoding encoding) { +static NSString * AFPercentEscapedQueryStringPairMemberFromStringWithEncoding(NSString *string, NSStringEncoding encoding) { // Escape characters that are legal in URIs, but have unintentional semantic significance when used in a query string parameter static NSString * const kAFLegalCharactersToBeEscaped = @":/.?&=;+!@$()~"; From c5e450f4af4092c113595efb4252016498102ce4 Mon Sep 17 00:00:00 2001 From: Avi Itskovich Date: Tue, 4 Sep 2012 17:32:00 -0400 Subject: [PATCH 56/81] Fix typo in multipart dir warning message --- AFNetworking/AFHTTPClient.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index 0596022..0ed05ef 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -705,7 +705,7 @@ static NSString * AFMultipartTemporaryFileDirectoryPath() { NSError *error = nil; if(![[NSFileManager defaultManager] createDirectoryAtPath:multipartTemporaryFilePath withIntermediateDirectories:YES attributes:nil error:&error]) { - NSLog(@"Failed to create multipary temporary file directory at %@", multipartTemporaryFilePath); + NSLog(@"Failed to create multipart temporary file directory at %@", multipartTemporaryFilePath); } }); From c0d7e11449b1f2c392f5aba656ab0706c0c15487 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 7 Sep 2012 16:45:12 -0700 Subject: [PATCH 57/81] [Issue #505] Handling missing content type correctly --- AFNetworking/AFHTTPRequestOperation.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 9d09e1c..1456eca 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -186,7 +186,15 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { return NO; } - return ![[self class] acceptableContentTypes] || [[[self class] acceptableContentTypes] containsObject:[self.response MIMEType]]; + // According to RFC 2616: + // Any HTTP/1.1 message containing an entity-body SHOULD include a Content-Type header field defining the media type of that body. If and only if the media type is not given by a Content-Type field, the recipient MAY attempt to guess the media type via inspection of its content and/or the name extension(s) of the URI used to identify the resource. If the media type remains unknown, the recipient SHOULD treat it as type "application/octet-stream". + // See http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html + NSString *contentType = [self.response MIMEType]; + if (!contentType) { + contentType = @"application/octet-stream"; + } + + return ![[self class] acceptableContentTypes] || [[[self class] acceptableContentTypes] containsObject:contentType]; } - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue { From 9ffd2226b3931bc206e598df759b9c3f725017a8 Mon Sep 17 00:00:00 2001 From: Stephen Tramer Date: Mon, 10 Sep 2012 13:17:04 -0700 Subject: [PATCH 58/81] [BUGFIX] Avoid common output stream setup errors, including immediately scheduling the stream on a runloop. --- AFNetworking/AFURLConnectionOperation.m | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index e1c0a4b..6f4838e 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -253,6 +253,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } - (void)setOutputStream:(NSOutputStream *)outputStream { + if (outputStream == _outputStream) { + return; + } + [self willChangeValueForKey:@"outputStream"]; [outputStream retain]; @@ -262,11 +266,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } _outputStream = outputStream; [self didChangeValueForKey:@"outputStream"]; - - NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; - for (NSString *runLoopMode in self.runLoopModes) { - [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode]; - } } #if __IPHONE_OS_VERSION_MIN_REQUIRED From 40c73c6588df887abcbae8a52a1ca67a1067ab33 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Thu, 13 Sep 2012 09:43:27 -0700 Subject: [PATCH 59/81] Updating link to documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5eb48b6..ae5cace 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Choose AFNetworking for your next project, or migrate over your existing project - [Download AFNetworking](https://github.com/AFNetworking/AFNetworking/zipball/master) and try out the included Mac and iPhone example apps - Read the ["Getting Started" guide](https://github.com/AFNetworking/AFNetworking/wiki/Getting-Started-with-AFNetworking), [FAQ](https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-FAQ), or [other articles in the wiki](https://github.com/AFNetworking/AFNetworking/wiki) -- Check out the [complete documentation](http://afnetworking.org/Documentation/) for a comprehensive look at the APIs available in AFNetworking +- Check out the [complete documentation](http://afnetworking.github.com/AFNetworking/) for a comprehensive look at the APIs available in AFNetworking - Watch the [NSScreencast episode about AFNetworking](http://nsscreencast.com/episodes/6-afnetworking) for a quick introduction to how to use it in your application - Questions? [Stack Overflow](http://stackoverflow.com/questions/tagged/afnetworking) is the best place to find answers From 95f2f5360427dba1b1ee3007df34ca3501ea922f Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 14 Sep 2012 09:01:54 -0700 Subject: [PATCH 60/81] Updating project settings --- Example/AFNetworking iOS Example.xcodeproj/project.pbxproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj index b97693c..7cb72b6 100644 --- a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj @@ -277,7 +277,7 @@ F8E469571395739C00DB05C8 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0440; + LastUpgradeCheck = 0450; ORGANIZATIONNAME = Gowalla; }; buildConfigurationList = F8E4695A1395739C00DB05C8 /* Build configuration list for PBXProject "AFNetworking iOS Example" */; From c8d9f79ef9f924a04a75121dc8c66340eb8670d6 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 14 Sep 2012 09:02:32 -0700 Subject: [PATCH 61/81] [#417] Fixing compilation error in Xcode 4.5 --- AFNetworking/AFHTTPRequestOperation.m | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 743f159..dd3fa40 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -23,6 +23,13 @@ #import "AFHTTPRequestOperation.h" #import +// Workaround for change in imp_implementationWithBlock() +#ifdef __IPHONE_6_0 + #define AF_CAST_TO_BLOCK id +#else + #define AF_CAST_TO_BLOCK __bridge void * +#endif + NSString * const kAFNetworkingIncompleteDownloadDirectoryName = @"Incomplete"; NSSet * AFContentTypesFromHTTPHeader(NSString *string) { @@ -54,9 +61,9 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) { return [NSSet setWithSet:mutableContentTypes]; } -static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, void *block) { +static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, id block) { Method originalMethod = class_getClassMethod(klass, selector); - IMP implementation = imp_implementationWithBlock((__bridge id)(block)); + IMP implementation = imp_implementationWithBlock((AF_CAST_TO_BLOCK)block); class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); } @@ -266,7 +273,7 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { + (void)addAcceptableStatusCodes:(NSIndexSet *)statusCodes { NSMutableIndexSet *mutableStatusCodes = [[NSMutableIndexSet alloc] initWithIndexSet:[self acceptableStatusCodes]]; [mutableStatusCodes addIndexes:statusCodes]; - AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), (__bridge void *)^(id _self) { + AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableStatusCodes), ^(id _self) { return mutableStatusCodes; }); } @@ -278,7 +285,7 @@ NSString * AFCreateIncompleteDownloadDirectoryPath(void) { + (void)addAcceptableContentTypes:(NSSet *)contentTypes { NSMutableSet *mutableContentTypes = [[NSMutableSet alloc] initWithSet:[self acceptableContentTypes] copyItems:YES]; [mutableContentTypes unionSet:contentTypes]; - AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), (__bridge void *)^(id _self) { + AFSwizzleClassMethodWithClassAndSelectorUsingBlock([self class], @selector(acceptableContentTypes), ^(id _self) { return mutableContentTypes; }); } From a4508ac997f8e0a1ac41bd3f9d3e01403eed03b5 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 14 Sep 2012 09:21:23 -0700 Subject: [PATCH 62/81] [Issue #507] Fixing potential issues with output stream runloop scheduling --- AFNetworking/AFHTTPRequestOperation.m | 5 +++++ AFNetworking/AFURLConnectionOperation.m | 15 +++++++++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 1456eca..db62120 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -314,6 +314,11 @@ didReceiveResponse:(NSURLResponse *)response } else { if ([[self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey] length] > 0) { self.outputStream = [NSOutputStream outputStreamToMemory]; + + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + for (NSString *runLoopMode in self.runLoopModes) { + [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode]; + } } } } diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index e1c0a4b..073c211 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -179,7 +179,11 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat self.request = urlRequest; self.outputStream = [NSOutputStream outputStreamToMemory]; - + NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; + for (NSString *runLoopMode in self.runLoopModes) { + [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode]; + } + self.state = AFOperationReadyState; return self; @@ -253,6 +257,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } - (void)setOutputStream:(NSOutputStream *)outputStream { + if (_outputStream == outputStream) { + return; + } + [self willChangeValueForKey:@"outputStream"]; [outputStream retain]; @@ -262,11 +270,6 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat } _outputStream = outputStream; [self didChangeValueForKey:@"outputStream"]; - - NSRunLoop *runLoop = [NSRunLoop currentRunLoop]; - for (NSString *runLoopMode in self.runLoopModes) { - [self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode]; - } } #if __IPHONE_OS_VERSION_MIN_REQUIRED From b8dff45fd88687b2f608efc9bbed76a99b46a54e Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 14 Sep 2012 10:17:53 -0700 Subject: [PATCH 63/81] Updating podspec to 0.10.1 --- AFNetworking.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index 904be11..f8ffa44 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = 'AFNetworking' - s.version = '0.10.0' + s.version = '0.10.1' s.license = 'MIT' s.summary = 'A delightful iOS and OS X networking framework.' s.homepage = 'https://github.com/AFNetworking/AFNetworking' s.authors = {'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@scottraymond.net'} - s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '0.10.0' } + s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '0.10.1' } s.source_files = 'AFNetworking' s.framework = 'SystemConfiguration' s.prefix_header_contents = "#import " From c1d3d840939af649df01283323871980b68c3a02 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 14 Sep 2012 10:34:10 -0700 Subject: [PATCH 64/81] Updating podspec to 1.0RC2 --- AFNetworking.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index f8ffa44..b1055c3 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = 'AFNetworking' - s.version = '0.10.1' + s.version = '1.0RC2' s.license = 'MIT' s.summary = 'A delightful iOS and OS X networking framework.' s.homepage = 'https://github.com/AFNetworking/AFNetworking' s.authors = {'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@scottraymond.net'} - s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '0.10.1' } + s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '1.0RC2' } s.source_files = 'AFNetworking' s.framework = 'SystemConfiguration' s.prefix_header_contents = "#import " From 501c4f18d481805cd0c6451468ac01238fddfcdc Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Fri, 14 Sep 2012 13:53:18 -0700 Subject: [PATCH 65/81] [Issue #516] Removing setHTTPShouldHandleCookies:NO from AFHTTPClient --- AFNetworking/AFHTTPClient.m | 1 - 1 file changed, 1 deletion(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index bcc2bbc..f49deca 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -421,7 +421,6 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url]; [request setHTTPMethod:method]; [request setAllHTTPHeaderFields:self.defaultHeaders]; - [request setHTTPShouldHandleCookies:NO]; if ([method isEqualToString:@"GET"] || [method isEqualToString:@"HEAD"]) { [request setHTTPShouldUsePipelining:YES]; From 925c926a64bc08973c509e7936c462d8c9cea124 Mon Sep 17 00:00:00 2001 From: Benoit Bourdon Date: Sat, 15 Sep 2012 12:41:58 +0200 Subject: [PATCH 66/81] dispatch_retain & dispatch_release no longer needed with latest ARC --- AFNetworking/AFHTTPClient.m | 18 ++++++++++++++ AFNetworking/AFHTTPRequestOperation.m | 34 ++++++++++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index f49deca..d4f1999 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -40,6 +40,22 @@ #import #endif +// Does ARC support support GCD objects? +// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ +#if TARGET_OS_IPHONE +#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later +#define NEEDS_DISPATCH_RETAIN_RELEASE 0 +#else // iOS 5.X or earlier +#define NEEDS_DISPATCH_RETAIN_RELEASE 1 +#endif +#else +#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later +#define NEEDS_DISPATCH_RETAIN_RELEASE 0 +#else +#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier +#endif +#endif + @interface AFMultipartFormData : NSObject - (id)initWithURLRequest:(NSMutableURLRequest *)request @@ -547,7 +563,9 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { completionBlock(operations); } }); +#if NEEDS_DISPATCH_RETAIN_RELEASE dispatch_release(dispatchGroup); +#endif }]; for (AFHTTPRequestOperation *operation in operations) { diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 398a9b8..747c8a3 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -30,6 +30,22 @@ #define AF_CAST_TO_BLOCK __bridge void * #endif +// Does ARC support support GCD objects? +// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ +#if TARGET_OS_IPHONE + #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later + #define NEEDS_DISPATCH_RETAIN_RELEASE 0 + #else // iOS 5.X or earlier + #define NEEDS_DISPATCH_RETAIN_RELEASE 1 + #endif +#else + #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later + #define NEEDS_DISPATCH_RETAIN_RELEASE 0 + #else + #define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier + #endif +#endif + NSSet * AFContentTypesFromHTTPHeader(NSString *string) { static NSCharacterSet *_skippedCharacterSet = nil; static dispatch_once_t onceToken; @@ -115,13 +131,17 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { @dynamic response; - (void)dealloc { - if (_successCallbackQueue) { + if (_successCallbackQueue) { +#if NEEDS_DISPATCH_RETAIN_RELEASE dispatch_release(_successCallbackQueue); +#endif _successCallbackQueue = NULL; } - if (_failureCallbackQueue) { - dispatch_release(_failureCallbackQueue); + if (_failureCallbackQueue) { +#if NEEDS_DISPATCH_RETAIN_RELEASE + dispatch_release(_failureCallbackQueue); +#endif _failureCallbackQueue = NULL; } } @@ -202,12 +222,16 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue { if (successCallbackQueue != _successCallbackQueue) { if (_successCallbackQueue) { +#if NEEDS_DISPATCH_RETAIN_RELEASE dispatch_release(_successCallbackQueue); +#endif _successCallbackQueue = NULL; } if (successCallbackQueue) { +#if NEEDS_DISPATCH_RETAIN_RELEASE dispatch_retain(successCallbackQueue); +#endif _successCallbackQueue = successCallbackQueue; } } @@ -216,12 +240,16 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (void)setFailureCallbackQueue:(dispatch_queue_t)failureCallbackQueue { if (failureCallbackQueue != _failureCallbackQueue) { if (_failureCallbackQueue) { +#if NEEDS_DISPATCH_RETAIN_RELEASE dispatch_release(_failureCallbackQueue); +#endif _failureCallbackQueue = NULL; } if (failureCallbackQueue) { +#if NEEDS_DISPATCH_RETAIN_RELEASE dispatch_retain(failureCallbackQueue); +#endif _failureCallbackQueue = failureCallbackQueue; } } From 94bbe4c1e8e413e37a78c48df1b1623c416d9755 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 17 Sep 2012 09:37:33 -0700 Subject: [PATCH 67/81] [Issue #521] Fixing AFContentTypesFromHTTPHeader to correctly handle comma-delimited content types --- AFNetworking/AFHTTPRequestOperation.m | 2 ++ 1 file changed, 2 insertions(+) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 398a9b8..6af2276 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -49,6 +49,8 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) { NSString *contentType = nil; if ([scanner scanUpToString:@";" intoString:&contentType]) { [scanner scanUpToString:@"," intoString:nil]; + } else { + [scanner scanUpToCharactersFromSet:_skippedCharacterSet intoString:&contentType]; } if (contentType) { From d2077e560928021b652e4e97f034e12f651e1d38 Mon Sep 17 00:00:00 2001 From: "jorge@miv.uk.com" Date: Mon, 17 Sep 2012 19:37:54 +0100 Subject: [PATCH 68/81] Fixed URLs to new documentation (under github domain) --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 3e6b482..ed5fe68 100644 --- a/README.md +++ b/README.md @@ -30,32 +30,32 @@ AFNetworking is architected to be as small and modular as possible, in order to - + - + - + - + - + - + - + - +
Core
AFURLConnectionOperationAFURLConnectionOperation An NSOperation that implements the NSURLConnection delegate methods.
HTTP Requests
AFHTTPRequestOperationAFHTTPRequestOperation A subclass of AFURLConnectionOperation for requests using the HTTP or HTTPS protocols. It encapsulates the concept of acceptable status codes and content types, which determine the success or failure of a request.
AFJSONRequestOperationAFJSONRequestOperation A subclass of AFHTTPRequestOperation for downloading and working with JSON response data.
AFXMLRequestOperationAFXMLRequestOperation A subclass of AFHTTPRequestOperation for downloading and working with XML response data.
AFPropertyListRequestOperationAFPropertyListRequestOperation A subclass of AFHTTPRequestOperation for downloading and deserializing objects with property list response data.
HTTP Client
AFHTTPClientAFHTTPClient Captures the common patterns of communicating with an web application over HTTP, including: @@ -74,11 +74,11 @@ AFNetworking is architected to be as small and modular as possible, in order to
Images
AFImageRequestOperationAFImageRequestOperation A subclass of AFHTTPRequestOperation for downloading and processing images.
UIImageView+AFNetworkingUIImageView+AFNetworking Adds methods to UIImageView for loading remote images asynchronously from a URL.
From 8c536f5f8d9bc831cee224876ac7d883d2328d80 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 17 Sep 2012 11:53:49 -0700 Subject: [PATCH 69/81] Refactoring macros for dispatch_release/retain fixes Fixing macro for changed method signature for imp_implementationWithBlock(), which actually depends on Xcode version (and thus a check for either __IPHONE_6_0 or __MAC_10_8 to be defined,regardless of the deployment target --- AFNetworking/AFHTTPClient.m | 23 +++++----------- AFNetworking/AFHTTPRequestOperation.m | 38 ++++++++++----------------- 2 files changed, 20 insertions(+), 41 deletions(-) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index d4f1999..fe18b2c 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -40,20 +40,10 @@ #import #endif -// Does ARC support support GCD objects? -// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ -#if TARGET_OS_IPHONE -#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later -#define NEEDS_DISPATCH_RETAIN_RELEASE 0 -#else // iOS 5.X or earlier -#define NEEDS_DISPATCH_RETAIN_RELEASE 1 -#endif -#else -#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later -#define NEEDS_DISPATCH_RETAIN_RELEASE 0 -#else -#define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier -#endif +// Workaround for management of dispatch_retain() / dispatch_release() by ARC with iOS 6 / Mac OS X 10.8 +#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && (!defined(__IPHONE_6_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0)) || \ + (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (!defined(__MAC_10_8) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8)) +#define AF_DISPATCH_RETAIN_RELEASE 1 #endif @interface AFMultipartFormData : NSObject @@ -338,8 +328,7 @@ static const void * AFNetworkReachabilityRetainCallback(const void *info) { return (__bridge_retained const void *)([(__bridge AFNetworkReachabilityStatusBlock)info copy]); } -static void AFNetworkReachabilityReleaseCallback(const void *info) { -} +static void AFNetworkReachabilityReleaseCallback(const void *info) {} - (void)startMonitoringNetworkReachability { [self stopMonitoringNetworkReachability]; @@ -563,7 +552,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { completionBlock(operations); } }); -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(dispatchGroup); #endif }]; diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 9aa34c9..95d0aa9 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -23,27 +23,17 @@ #import "AFHTTPRequestOperation.h" #import -// Workaround for change in imp_implementationWithBlock() -#ifdef __IPHONE_6_0 - #define AF_CAST_TO_BLOCK id +// Workaround for change in imp_implementationWithBlock() with Xcode 4.5 +#if defined(__IPHONE_6_0) || defined(__MAC_10_8) +#define AF_CAST_TO_BLOCK id #else - #define AF_CAST_TO_BLOCK __bridge void * +#define AF_CAST_TO_BLOCK __bridge void * #endif -// Does ARC support support GCD objects? -// It does if the minimum deployment target is iOS 6+ or Mac OS X 8+ -#if TARGET_OS_IPHONE - #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 60000 // iOS 6.0 or later - #define NEEDS_DISPATCH_RETAIN_RELEASE 0 - #else // iOS 5.X or earlier - #define NEEDS_DISPATCH_RETAIN_RELEASE 1 - #endif -#else - #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1080 // Mac OS X 10.8 or later - #define NEEDS_DISPATCH_RETAIN_RELEASE 0 - #else - #define NEEDS_DISPATCH_RETAIN_RELEASE 1 // Mac OS X 10.7 or earlier - #endif +// Workaround for management of dispatch_retain() / dispatch_release() by ARC with iOS 6 / Mac OS X 10.8 +#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && (!defined(__IPHONE_6_0) || __IPHONE_OS_VERSION_MIN_REQUIRED < __IPHONE_6_0)) || \ + (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && (!defined(__MAC_10_8) || __MAC_OS_X_VERSION_MIN_REQUIRED < __MAC_10_8)) +#define AF_DISPATCH_RETAIN_RELEASE 1 #endif NSSet * AFContentTypesFromHTTPHeader(NSString *string) { @@ -134,14 +124,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (void)dealloc { if (_successCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(_successCallbackQueue); #endif _successCallbackQueue = NULL; } if (_failureCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(_failureCallbackQueue); #endif _failureCallbackQueue = NULL; @@ -224,14 +214,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (void)setSuccessCallbackQueue:(dispatch_queue_t)successCallbackQueue { if (successCallbackQueue != _successCallbackQueue) { if (_successCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(_successCallbackQueue); #endif _successCallbackQueue = NULL; } if (successCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_retain(successCallbackQueue); #endif _successCallbackQueue = successCallbackQueue; @@ -242,14 +232,14 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { - (void)setFailureCallbackQueue:(dispatch_queue_t)failureCallbackQueue { if (failureCallbackQueue != _failureCallbackQueue) { if (_failureCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_release(_failureCallbackQueue); #endif _failureCallbackQueue = NULL; } if (failureCallbackQueue) { -#if NEEDS_DISPATCH_RETAIN_RELEASE +#if AF_DISPATCH_RETAIN_RELEASE dispatch_retain(failureCallbackQueue); #endif _failureCallbackQueue = failureCallbackQueue; From 7cd20077dc4d367b53e599464ccc02c4bc867187 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 17 Sep 2012 12:01:24 -0700 Subject: [PATCH 70/81] Updating 1.0RC2 podspec to add requires_arc flag --- AFNetworking.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index b1055c3..dee1f1a 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -9,4 +9,5 @@ Pod::Spec.new do |s| s.source_files = 'AFNetworking' s.framework = 'SystemConfiguration' s.prefix_header_contents = "#import " + s.requires_arc = true end From 2b89ad4c6044fadb93b663758f1d708fb894bc8e Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 17 Sep 2012 12:03:26 -0700 Subject: [PATCH 71/81] Updating podspec to 1.0RC3 --- AFNetworking.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index dee1f1a..c41389d 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -1,11 +1,11 @@ Pod::Spec.new do |s| s.name = 'AFNetworking' - s.version = '1.0RC2' + s.version = '1.0' s.license = 'MIT' s.summary = 'A delightful iOS and OS X networking framework.' s.homepage = 'https://github.com/AFNetworking/AFNetworking' s.authors = {'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@scottraymond.net'} - s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '1.0RC2' } + s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '1.0RC3' } s.source_files = 'AFNetworking' s.framework = 'SystemConfiguration' s.prefix_header_contents = "#import " From f0e6b53fe71782435472bd309c02d2697a9c64e4 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 17 Sep 2012 12:10:43 -0700 Subject: [PATCH 72/81] Synchronoizing podspec with CocoaPods version --- AFNetworking.podspec | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index c41389d..064ef40 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -4,10 +4,10 @@ Pod::Spec.new do |s| s.license = 'MIT' s.summary = 'A delightful iOS and OS X networking framework.' s.homepage = 'https://github.com/AFNetworking/AFNetworking' - s.authors = {'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@scottraymond.net'} + s.authors = {'Mattt Thompson' => 'm@mattt.me', 'Scott Raymond' => 'sco@gowalla.com'} s.source = { :git => 'https://github.com/AFNetworking/AFNetworking.git', :tag => '1.0RC3' } s.source_files = 'AFNetworking' - s.framework = 'SystemConfiguration' - s.prefix_header_contents = "#import " s.requires_arc = true + + s.framework = 'SystemConfiguration' end From 3589d25652034b71ca408eadb60de4ff903a44e4 Mon Sep 17 00:00:00 2001 From: Blake Watters Date: Wed, 19 Sep 2012 16:00:15 -0400 Subject: [PATCH 73/81] Set `_networkReachability` to `NULL` after releasing. fixes AFNetworking/AFNetworking#529 --- AFNetworking/AFHTTPClient.m | 1 + 1 file changed, 1 insertion(+) diff --git a/AFNetworking/AFHTTPClient.m b/AFNetworking/AFHTTPClient.m index fe18b2c..6d47148 100644 --- a/AFNetworking/AFHTTPClient.m +++ b/AFNetworking/AFHTTPClient.m @@ -366,6 +366,7 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) {} if (_networkReachability) { SCNetworkReachabilityUnscheduleFromRunLoop(_networkReachability, CFRunLoopGetMain(), (CFStringRef)NSRunLoopCommonModes); CFRelease(_networkReachability); + _networkReachability = NULL; } } From d59197bca06ea2fd86a8b3f8ad5cdb9f29b35ec7 Mon Sep 17 00:00:00 2001 From: Peyman Date: Wed, 19 Sep 2012 16:41:52 -0700 Subject: [PATCH 74/81] Fix parsing of HTTP Accept headers --- AFNetworking/AFHTTPRequestOperation.m | 43 ++++++++++++++------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 95d0aa9..f55fbda 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -37,33 +37,34 @@ #endif NSSet * AFContentTypesFromHTTPHeader(NSString *string) { - static NSCharacterSet *_skippedCharacterSet = nil; + static NSCharacterSet *_trimCharacterSet = nil; static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - _skippedCharacterSet = [NSCharacterSet characterSetWithCharactersInString:@" ,"]; + _trimCharacterSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; }); - + if (!string) { return nil; } - - NSScanner *scanner = [NSScanner scannerWithString:string]; - scanner.charactersToBeSkipped = _skippedCharacterSet; - - NSMutableSet *mutableContentTypes = [NSMutableSet set]; - while (![scanner isAtEnd]) { - NSString *contentType = nil; - if ([scanner scanUpToString:@";" intoString:&contentType]) { - [scanner scanUpToString:@"," intoString:nil]; - } else { - [scanner scanUpToCharactersFromSet:_skippedCharacterSet intoString:&contentType]; - } - - if (contentType) { - [mutableContentTypes addObject:contentType]; - } - } - + + NSArray *mediaRanges = [string componentsSeparatedByString:@","]; + + NSMutableSet *mutableContentTypes = [NSMutableSet setWithCapacity:mediaRanges.count]; + + [mediaRanges enumerateObjectsUsingBlock:^(NSString *mediaRange, NSUInteger idx, BOOL *stop) { + + NSRange startOfParameters = [mediaRange rangeOfString:@";"]; + if (startOfParameters.location != NSNotFound) { + mediaRange = [mediaRange substringToIndex:startOfParameters.location]; + } + + mediaRange = [mediaRange stringByTrimmingCharactersInSet:_trimCharacterSet]; + + if (mediaRange.length > 0) + [mutableContentTypes addObject:mediaRange]; + + }]; + return [NSSet setWithSet:mutableContentTypes]; } From 510e0be4d2ba6990cbbb4fd7e007ff2f43b66f5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Fri, 21 Sep 2012 10:33:17 +0200 Subject: [PATCH 75/81] Re-add the prefix header import of SystemConfiguration to the podspec. --- AFNetworking.podspec | 1 + 1 file changed, 1 insertion(+) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index 064ef40..2c1f68c 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -10,4 +10,5 @@ Pod::Spec.new do |s| s.requires_arc = true s.framework = 'SystemConfiguration' + s.prefix_header_contents = "#import " end From 45880fd9a019c6f9f7f5a6cf05f5537605a0d870 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 24 Sep 2012 08:26:00 -0700 Subject: [PATCH 76/81] Minor refactoring and reformatting --- AFNetworking/AFHTTPRequestOperation.m | 28 ++++++++++----------------- 1 file changed, 10 insertions(+), 18 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index f55fbda..1021681 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -37,32 +37,24 @@ #endif NSSet * AFContentTypesFromHTTPHeader(NSString *string) { - static NSCharacterSet *_trimCharacterSet = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - _trimCharacterSet = [NSCharacterSet whitespaceAndNewlineCharacterSet]; - }); - if (!string) { return nil; } NSArray *mediaRanges = [string componentsSeparatedByString:@","]; - NSMutableSet *mutableContentTypes = [NSMutableSet setWithCapacity:mediaRanges.count]; [mediaRanges enumerateObjectsUsingBlock:^(NSString *mediaRange, NSUInteger idx, BOOL *stop) { - - NSRange startOfParameters = [mediaRange rangeOfString:@";"]; - if (startOfParameters.location != NSNotFound) { - mediaRange = [mediaRange substringToIndex:startOfParameters.location]; - } - - mediaRange = [mediaRange stringByTrimmingCharactersInSet:_trimCharacterSet]; - - if (mediaRange.length > 0) - [mutableContentTypes addObject:mediaRange]; - + NSRange parametersRange = [mediaRange rangeOfString:@";"]; + if (parametersRange.location != NSNotFound) { + mediaRange = [mediaRange substringToIndex:parametersRange.location]; + } + + mediaRange = [mediaRange stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]; + + if (mediaRange.length > 0) { + [mutableContentTypes addObject:mediaRange]; + } }]; return [NSSet setWithSet:mutableContentTypes]; From df140116b861cb9cc6c1d5e7130a129a4a637a0f Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 24 Sep 2012 08:26:38 -0700 Subject: [PATCH 77/81] Moving AFSwizzleClassMethodWithClassAndSelectorUsingBlock function --- AFNetworking/AFHTTPRequestOperation.m | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperation.m b/AFNetworking/AFHTTPRequestOperation.m index 1021681..bc7095d 100644 --- a/AFNetworking/AFHTTPRequestOperation.m +++ b/AFNetworking/AFHTTPRequestOperation.m @@ -60,12 +60,6 @@ NSSet * AFContentTypesFromHTTPHeader(NSString *string) { return [NSSet setWithSet:mutableContentTypes]; } -static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, id block) { - Method originalMethod = class_getClassMethod(klass, selector); - IMP implementation = imp_implementationWithBlock((AF_CAST_TO_BLOCK)block); - class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); -} - static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { NSMutableString *string = [NSMutableString string]; @@ -96,6 +90,12 @@ static NSString * AFStringFromIndexSet(NSIndexSet *indexSet) { return string; } +static void AFSwizzleClassMethodWithClassAndSelectorUsingBlock(Class klass, SEL selector, id block) { + Method originalMethod = class_getClassMethod(klass, selector); + IMP implementation = imp_implementationWithBlock((AF_CAST_TO_BLOCK)block); + class_replaceMethod(objc_getMetaClass([NSStringFromClass(klass) UTF8String]), selector, implementation, method_getTypeEncoding(originalMethod)); +} + #pragma mark - @interface AFHTTPRequestOperation () From f523744cf055f63b3229edd6d967a447922173e9 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Mon, 24 Sep 2012 08:27:18 -0700 Subject: [PATCH 78/81] Minor restructuring of project file and app delegate in example --- .../project.pbxproj | 4 +-- .../project.pbxproj | 4 +-- Example/AppDelegate.m | 26 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj index 899632e..b1ee68d 100644 --- a/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking Mac Example.xcodeproj/project.pbxproj @@ -112,6 +112,8 @@ children = ( F8129C311591073C009BFE23 /* AFTwitterAPIClient.h */, F8129C251591073C009BFE23 /* AFTwitterAPIClient.m */, + F8129C7615910C40009BFE23 /* AppDelegate.h */, + F8129C7515910C40009BFE23 /* AppDelegate.m */, F8129C291591073C009BFE23 /* Models */, F8129C061591061B009BFE23 /* Supporting Files */, ); @@ -122,8 +124,6 @@ F8129C061591061B009BFE23 /* Supporting Files */ = { isa = PBXGroup; children = ( - F8129C7615910C40009BFE23 /* AppDelegate.h */, - F8129C7515910C40009BFE23 /* AppDelegate.m */, F8129C6E15910B15009BFE23 /* main.m */, F8129C7015910B3E009BFE23 /* MainMenu.xib */, ); diff --git a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj index f193529..6623ce0 100644 --- a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj @@ -172,6 +172,8 @@ F8E4696A1395739D00DB05C8 /* Classes */ = { isa = PBXGroup; children = ( + F8129C7315910C37009BFE23 /* AppDelegate.h */, + F8129C7215910C37009BFE23 /* AppDelegate.m */, F8DA09C91396AB690057D0CC /* Models */, F8DA09CC1396AB690057D0CC /* Views */, F8DA09C61396AB690057D0CC /* Controllers */, @@ -186,8 +188,6 @@ children = ( F8DA09E31396AC040057D0CC /* main.m */, F8129C3815910830009BFE23 /* Prefix.pch */, - F8129C7315910C37009BFE23 /* AppDelegate.h */, - F8129C7215910C37009BFE23 /* AppDelegate.m */, F8E4696C1395739D00DB05C8 /* iOS-Info.plist */, ); name = "Supporting Files"; diff --git a/Example/AppDelegate.m b/Example/AppDelegate.m index c5b56a1..6e8de56 100644 --- a/Example/AppDelegate.m +++ b/Example/AppDelegate.m @@ -37,19 +37,19 @@ didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:4 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil]; [NSURLCache setSharedURLCache:URLCache]; - - [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; - - UITableViewController *viewController = [[PublicTimelineViewController alloc] initWithStyle:UITableViewStylePlain]; - self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; - self.navigationController.navigationBar.tintColor = [UIColor darkGrayColor]; - - self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; - self.window.backgroundColor = [UIColor whiteColor]; - self.window.rootViewController = self.navigationController; - [self.window makeKeyAndVisible]; - - return YES; + + [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; + + UITableViewController *viewController = [[PublicTimelineViewController alloc] initWithStyle:UITableViewStylePlain]; + self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; + self.navigationController.navigationBar.tintColor = [UIColor darkGrayColor]; + + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.window.backgroundColor = [UIColor whiteColor]; + self.window.rootViewController = self.navigationController; + [self.window makeKeyAndVisible]; + + return YES; } @end From e35a88fdef629b35f8d9706b2ad92c5289485f58 Mon Sep 17 00:00:00 2001 From: ap4y Date: Fri, 21 Sep 2012 17:22:07 +0400 Subject: [PATCH 79/81] Preventing negative values for the activity indicator counter --- AFNetworking/AFNetworkActivityIndicatorManager.m | 3 +++ 1 file changed, 3 insertions(+) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index 5672773..ec3eabc 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -118,6 +118,9 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.17; } - (void)decrementActivityCount { + if (_activityCount == 0) { + return; + } [self willChangeValueForKey:@"activityCount"]; @synchronized(self) { _activityCount--; From 68adeab76897661b454e0104061d9a9b56750ef1 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 25 Sep 2012 07:15:02 -0700 Subject: [PATCH 80/81] Use MAX to constrain _activityCount to non-negative numbers --- AFNetworking/AFNetworkActivityIndicatorManager.m | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.m b/AFNetworking/AFNetworkActivityIndicatorManager.m index ec3eabc..32553fc 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.m +++ b/AFNetworking/AFNetworkActivityIndicatorManager.m @@ -118,12 +118,9 @@ static NSTimeInterval const kAFNetworkActivityIndicatorInvisibilityDelay = 0.17; } - (void)decrementActivityCount { - if (_activityCount == 0) { - return; - } [self willChangeValueForKey:@"activityCount"]; @synchronized(self) { - _activityCount--; + _activityCount = MAX(_activityCount - 1, 0); } [self didChangeValueForKey:@"activityCount"]; [self updateNetworkActivityIndicatorVisibilityDelayed]; From aa55210181e26c695b7cc53ab3ecf7a43043ae97 Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 25 Sep 2012 07:24:52 -0700 Subject: [PATCH 81/81] Adding additional documentation about usage for AFNetworkActivityIndicatorManager --- AFNetworking/AFNetworkActivityIndicatorManager.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFNetworkActivityIndicatorManager.h b/AFNetworking/AFNetworkActivityIndicatorManager.h index 929c48a..2b4d54c 100644 --- a/AFNetworking/AFNetworkActivityIndicatorManager.h +++ b/AFNetworking/AFNetworkActivityIndicatorManager.h @@ -30,7 +30,14 @@ /** `AFNetworkActivityIndicatorManager` manages the state of the network activity indicator in the status bar. When enabled, it will listen for notifications indicating that a network request operation has started or finished, and start or stop animating the indicator accordingly. The number of active requests is incremented and decremented much like a stack or a semaphore, and the activity indicator will animate so long as that number is greater than zero. - @discussion By setting `isNetworkActivityIndicatorVisible` to `YES` for `sharedManager`, the network activity indicator will show and hide automatically as requests start and finish. You should not ever need to call `incrementActivityCount` or `decrementActivityCount` yourself. + You should enable the shared instance of `AFNetworkActivityIndicatorManager` when your application finishes launching. In `AppDelegate application:didFinishLaunchingWithOptions:` you can do so with the following code: + + [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; + + By setting `isNetworkActivityIndicatorVisible` to `YES` for `sharedManager`, the network activity indicator will show and hide automatically as requests start and finish. You should not ever need to call `incrementActivityCount` or `decrementActivityCount` yourself. + + See the Apple Human Interface Guidelines section about the Network Activity Indicator for more information: + http://developer.apple.com/library/iOS/#documentation/UserExperience/Conceptual/MobileHIG/UIElementGuidelines/UIElementGuidelines.html#//apple_ref/doc/uid/TP40006556-CH13-SW44 */ @interface AFNetworkActivityIndicatorManager : NSObject