From 680a478b36fe631db2c3ea10868231bb42c0f15a Mon Sep 17 00:00:00 2001 From: Julien Cayzac Date: Thu, 30 Jul 2015 14:17:44 +0900 Subject: [PATCH 01/40] Fix #2864: allow empty x-www-form-urlencoded bodies --- AFNetworking/AFURLRequestSerialization.m | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index d64ed03621..6373201f13 100644 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -486,8 +486,8 @@ - (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request } }]; + NSString *query = nil; if (parameters) { - NSString *query = nil; if (self.queryStringSerialization) { NSError *serializationError; query = self.queryStringSerialization(request, parameters, &serializationError); @@ -506,15 +506,18 @@ - (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request break; } } + } - if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) { + if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) { + if (query) { mutableRequest.URL = [NSURL URLWithString:[[mutableRequest.URL absoluteString] stringByAppendingFormat:mutableRequest.URL.query ? @"&%@" : @"?%@", query]]; - } else { - if (![mutableRequest valueForHTTPHeaderField:@"Content-Type"]) { - [mutableRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; - } - [mutableRequest setHTTPBody:[query dataUsingEncoding:self.stringEncoding]]; } + } else { + // #2864: an empty string is a valid x-www-form-urlencoded payload + if (![mutableRequest valueForHTTPHeaderField:@"Content-Type"]) { + [mutableRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; + } + [mutableRequest setHTTPBody:[query ?: @"" dataUsingEncoding:self.stringEncoding]]; } return mutableRequest; From 76fa71824d990a2e35dc67b1df4ce898a41a2eb1 Mon Sep 17 00:00:00 2001 From: Julien Cayzac Date: Tue, 4 Aug 2015 14:46:27 +0900 Subject: [PATCH 02/40] Added unit tests for #2864 --- Tests/Tests/AFHTTPRequestSerializationTests.m | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/Tests/Tests/AFHTTPRequestSerializationTests.m b/Tests/Tests/AFHTTPRequestSerializationTests.m index f9226fc691..6f8de1f4f8 100644 --- a/Tests/Tests/AFHTTPRequestSerializationTests.m +++ b/Tests/Tests/AFHTTPRequestSerializationTests.m @@ -65,6 +65,34 @@ - (void)setUp { #pragma mark - +- (void)testThatAFHTTPRequestSerializationSerializesPOSTRequestsProperly { + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com"]]; + request.HTTPMethod = @"POST"; + + NSURLRequest *serializedRequest = [self.requestSerializer requestBySerializingRequest:request withParameters:@{@"key":@"value"} error:nil]; + NSString *contentType = serializedRequest.allHTTPHeaderFields[@"Content-Type"]; + + XCTAssertNotNil(contentType); + XCTAssertEqualObjects(contentType, @"application/x-www-form-urlencoded"); + + XCTAssertNotNil(serializedRequest.HTTPBody); + XCTAssertEqualObjects(serializedRequest.HTTPBody, [@"key=value" dataUsingEncoding:NSUTF8StringEncoding]); +} + +- (void)testThatAFHTTPRequestSerializationSerializesPOSTRequestsProperlyWhenNoParameterIsProvided { + NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com"]]; + request.HTTPMethod = @"POST"; + + NSURLRequest *serializedRequest = [self.requestSerializer requestBySerializingRequest:request withParameters:nil error:nil]; + NSString *contentType = serializedRequest.allHTTPHeaderFields[@"Content-Type"]; + + XCTAssertNotNil(contentType); + XCTAssertEqualObjects(contentType, @"application/x-www-form-urlencoded"); + + XCTAssertNotNil(serializedRequest.HTTPBody); + XCTAssertEqualObjects(serializedRequest.HTTPBody, [NSData data]); +} + - (void)testThatAFHTTPRequestSerialiationSerializesQueryParametersCorrectly { NSURLRequest *originalRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://example.com"]]; NSURLRequest *serializedRequest = [self.requestSerializer requestBySerializingRequest:originalRequest withParameters:@{@"key":@"value"} error:nil]; From 9cb72ef8448cb4d9fac119fb4db71dced2d2519d Mon Sep 17 00:00:00 2001 From: Julien Cayzac Date: Tue, 4 Aug 2015 14:46:27 +0900 Subject: [PATCH 03/40] Added unit tests for #2864 --- AFNetworking/AFURLRequestSerialization.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index 6373201f13..21bdf1cf2e 100644 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -514,10 +514,13 @@ - (NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request } } else { // #2864: an empty string is a valid x-www-form-urlencoded payload + if (!query) { + query = @""; + } if (![mutableRequest valueForHTTPHeaderField:@"Content-Type"]) { [mutableRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; } - [mutableRequest setHTTPBody:[query ?: @"" dataUsingEncoding:self.stringEncoding]]; + [mutableRequest setHTTPBody:[query dataUsingEncoding:self.stringEncoding]]; } return mutableRequest; From e0815dacfabc7a15c14ad87de74b63a071b17fa8 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 13 Oct 2015 10:43:52 -0500 Subject: [PATCH 04/40] Migrated to Travis Matrix --- .gitignore | 1 - .travis.yml | 38 ++++- .../xcschemes/AFNetworking Example.xcscheme | 91 +++++++++++ .../project.pbxproj | 2 + .../AFNetworking iOS Example.xcscheme | 91 +++++++++++ .../xcschemes/AFNetworking watchOS.xcscheme | 141 ++++++++++++++++++ .../xcschemes/Today Extension.xcscheme | 108 ++++++++++++++ .../AFNetworking watchOS Extension/Info.plist | 2 +- Example/AFNetworking watchOS/Info.plist | 2 +- Example/Today Extension/Info.plist | 2 +- Rakefile | 89 ----------- .../xcschemes/OS X Tests.xcscheme | 56 +++++++ .../xcshareddata/xcschemes/iOS Tests.xcscheme | 56 +++++++ Tests/Tests/AFNetworkActivityManagerTests.m | 97 ++++++------ 14 files changed, 625 insertions(+), 151 deletions(-) create mode 100644 Example/AFNetworking OS X Example.xcodeproj/xcshareddata/xcschemes/AFNetworking Example.xcscheme create mode 100644 Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/AFNetworking iOS Example.xcscheme create mode 100644 Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/AFNetworking watchOS.xcscheme create mode 100644 Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/Today Extension.xcscheme delete mode 100644 Rakefile create mode 100644 Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/OS X Tests.xcscheme create mode 100644 Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/iOS Tests.xcscheme diff --git a/.gitignore b/.gitignore index d9b2144d3b..3ed6abd5fd 100644 --- a/.gitignore +++ b/.gitignore @@ -18,4 +18,3 @@ DerivedData .idea/ Tests/Pods Tests/Podfile.lock -Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/ diff --git a/.travis.yml b/.travis.yml index 23db5e2fa1..c531ee656f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,36 @@ language: objective-c osx_image: xcode7 +sudo: false +env: + global: + - LC_CTYPE=en_US.UTF-8 + - LANG=en_US.UTF-8 + matrix: + - DESTINATION="OS=9.0,name=iPhone 6 Plus" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO" + - DESTINATION="OS=8.1,name=iPhone 4S" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="YES" + - DESTINATION="OS=8.2,name=iPhone 5" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" + - DESTINATION="OS=8.3,name=iPhone 5S" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" + - DESTINATION="OS=8.4,name=iPhone 6" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" +# TESTS ARE CURRENTLY DISABLED FOR MAC OS X DUE TO THIS ISSUE: https://github.com/travis-ci/travis-ci/issues/4904 + - DESTINATION="arch=x86_64" TEST_SCHEME="OS X Tests" SDK=macosx10.11 EXAMPLE_SCHEME="AFNetworking Example" RUN_TESTS="NO" BUILD_EXAMPLE="YES" POD_LINT="NO" before_install: - - gem install cocoapods --no-rdoc --no-ri --no-document --quiet - - gem install xcpretty --no-rdoc --no-ri --no-document --quiet - - cd Tests && pod install && cd $TRAVIS_BUILD_DIR -script: rake test - + - gem install cocoapods --no-rdoc --no-ri --no-document --quiet + - gem install xcpretty --no-rdoc --no-ri --no-document --quiet + - cd Tests && pod install && cd $TRAVIS_BUILD_DIR +script: + - set -o pipefail + - xcodebuild -version + - xcodebuild -showsdks + - if [ $RUN_TESTS == "YES" ]; then + xcodebuild -workspace AFNetworking.xcworkspace -scheme "$TEST_SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Debug ONLY_ACTIVE_ARCH=NO test | xcpretty -c; + xcodebuild -workspace AFNetworking.xcworkspace -scheme "$TEST_SCHEME" -sdk "$SDK" -destination "$DESTINATION" -configuration Release ONLY_ACTIVE_ARCH=NO test | xcpretty -c; + fi + - if [ $BUILD_EXAMPLE == "YES" ]; then + xcodebuild -workspace AFNetworking.xcworkspace -scheme "$EXAMPLE_SCHEME" -destination "$DESTINATION" + -configuration Debug ONLY_ACTIVE_ARCH=NO build | xcpretty -c; + xcodebuild -workspace AFNetworking.xcworkspace -scheme "$EXAMPLE_SCHEME" -destination "$DESTINATION" + -configuration Release ONLY_ACTIVE_ARCH=NO build | xcpretty -c; + fi + - if [ $POD_LINT == "YES" ]; then + pod lib lint --quick; + fi \ No newline at end of file diff --git a/Example/AFNetworking OS X Example.xcodeproj/xcshareddata/xcschemes/AFNetworking Example.xcscheme b/Example/AFNetworking OS X Example.xcodeproj/xcshareddata/xcschemes/AFNetworking Example.xcscheme new file mode 100644 index 0000000000..6ff0d3e207 --- /dev/null +++ b/Example/AFNetworking OS X Example.xcodeproj/xcshareddata/xcschemes/AFNetworking Example.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj index 9d93a32d97..63466c4a37 100644 --- a/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking iOS Example.xcodeproj/project.pbxproj @@ -1218,6 +1218,7 @@ 29900D261B6FB14000DE5662 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 29900D291B6FB14000DE5662 /* Build configuration list for PBXNativeTarget "AFNetworking watchOS" */ = { isa = XCConfigurationList; @@ -1226,6 +1227,7 @@ 29900D241B6FB14000DE5662 /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; EBE11F591B62EDD200753127 /* Build configuration list for PBXNativeTarget "Today Extension" */ = { isa = XCConfigurationList; diff --git a/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/AFNetworking iOS Example.xcscheme b/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/AFNetworking iOS Example.xcscheme new file mode 100644 index 0000000000..bf0cd70e81 --- /dev/null +++ b/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/AFNetworking iOS Example.xcscheme @@ -0,0 +1,91 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/AFNetworking watchOS.xcscheme b/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/AFNetworking watchOS.xcscheme new file mode 100644 index 0000000000..ec26092353 --- /dev/null +++ b/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/AFNetworking watchOS.xcscheme @@ -0,0 +1,141 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/Today Extension.xcscheme b/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/Today Extension.xcscheme new file mode 100644 index 0000000000..32843f63b0 --- /dev/null +++ b/Example/AFNetworking iOS Example.xcodeproj/xcshareddata/xcschemes/Today Extension.xcscheme @@ -0,0 +1,108 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Example/AFNetworking watchOS Extension/Info.plist b/Example/AFNetworking watchOS Extension/Info.plist index b752306b9f..d932c4e866 100644 --- a/Example/AFNetworking watchOS Extension/Info.plist +++ b/Example/AFNetworking watchOS Extension/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1 + 1.0.0 NSExtension NSExtensionAttributes diff --git a/Example/AFNetworking watchOS/Info.plist b/Example/AFNetworking watchOS/Info.plist index 6c4f88c560..557baf0e30 100644 --- a/Example/AFNetworking watchOS/Info.plist +++ b/Example/AFNetworking watchOS/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1 + 1.0.0 UISupportedInterfaceOrientations UIInterfaceOrientationPortrait diff --git a/Example/Today Extension/Info.plist b/Example/Today Extension/Info.plist index 13eb2a2ece..5b7906020b 100644 --- a/Example/Today Extension/Info.plist +++ b/Example/Today Extension/Info.plist @@ -21,7 +21,7 @@ CFBundleSignature ???? CFBundleVersion - 1 + 1.0.0 NSExtension NSExtensionMainStoryboard diff --git a/Rakefile b/Rakefile deleted file mode 100644 index 45172b69d0..0000000000 --- a/Rakefile +++ /dev/null @@ -1,89 +0,0 @@ -include FileUtils::Verbose - -namespace :test do - task :prepare do - mkdir_p "Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes" - cp Dir.glob('Tests/Schemes/*.xcscheme'), "Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/" - end - - desc "Run the AFNetworking Tests for iOS" - task :ios => :prepare do - simulators = get_ios_simulators - destinations = Array.new - simulators.each {|version, available_simulators| - destinations.push("platform=iOS Simulator,OS=#{available_simulators[:runtime]},name=#{available_simulators[:device_names][0]}") - puts "Will run tests for iOS Simulator on iOS #{available_simulators[:runtime]} using #{available_simulators[:device_names][0]}" - } - - run_tests('iOS Tests', 'iphonesimulator', destinations) - tests_failed('iOS') unless $?.success? - end - - desc "Run the AFNetworking Tests for Mac OS X" - task :osx => :prepare do - run_tests('OS X Tests', 'macosx', ['platform=OS X,arch=x86_64']) - tests_failed('OSX') unless $?.success? - end -end - -desc "Run the AFNetworking Tests for iOS & Mac OS X" -task :test do - Rake::Task['test:ios'].invoke - Rake::Task['test:osx'].invoke if is_mavericks_or_above -end - -task :default => 'test' - - -private - -def run_tests(scheme, sdk, destinations) - destinations = destinations.map! { |destination| "-destination \'#{destination}\'" }.join(' ') - sh("xcodebuild -workspace AFNetworking.xcworkspace -scheme '#{scheme}' -sdk '#{sdk}' #{destinations} -configuration Release clean test | xcpretty -c ; exit ${PIPESTATUS[0]}") rescue nil -end - -def is_mavericks_or_above - osx_version = `sw_vers -productVersion`.chomp - Gem::Version.new(osx_version) >= Gem::Version.new('10.9') -end - -def tests_failed(platform) - puts red("#{platform} unit tests failed") - exit $?.exitstatus -end - -def red(string) - "\033[0;31m! #{string}" -end - -def get_ios_simulators - device_section_regex = /== Devices ==(.*?)(?=(?===)|\z)/m - runtime_section_regex = /== Runtimes ==(.*?)(?=(?===)|\z)/m - runtime_version_regex = /iOS (.*) \((.*) - .*?\) (\(.*\))/ - xcrun_output = `xcrun simctl list` - puts "Available iOS Simulators: \n#{xcrun_output}" - - simulators = Hash.new - runtimes_section = xcrun_output.scan(runtime_section_regex)[0] - runtimes_section[0].scan(runtime_version_regex) {|result| - if result[2] !~ /unavailable/ - simulators[result[0]] = Hash.new - simulators[result[0]][:runtime] = result[1] - end - } - - device_section = xcrun_output.scan(device_section_regex)[0] - version_regex = /-- iOS (.*?) --(.*?)(?=(?=-- .*? --)|\z)/m - simulator_name_regex = /(.*) \([A-F0-9-]*\) \(.*\)/ - device_section[0].scan(version_regex) {|result| - if simulators.has_key?(result[0]) - simulators[result[0]][:device_names] = Array.new - result[1].scan(simulator_name_regex) { |device_name_result| - device_name = device_name_result[0].strip - simulators[result[0]][:device_names].push(device_name) - } - end - } - return simulators -end - diff --git a/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/OS X Tests.xcscheme b/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/OS X Tests.xcscheme new file mode 100644 index 0000000000..4891d6dcbd --- /dev/null +++ b/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/OS X Tests.xcscheme @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/iOS Tests.xcscheme b/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/iOS Tests.xcscheme new file mode 100644 index 0000000000..1d8f0f6248 --- /dev/null +++ b/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/iOS Tests.xcscheme @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tests/Tests/AFNetworkActivityManagerTests.m b/Tests/Tests/AFNetworkActivityManagerTests.m index 40b1c4aed4..2f58c1835b 100644 --- a/Tests/Tests/AFNetworkActivityManagerTests.m +++ b/Tests/Tests/AFNetworkActivityManagerTests.m @@ -22,12 +22,11 @@ #import "AFTestCase.h" #import "AFNetworkActivityIndicatorManager.h" -#import "AFHTTPRequestOperation.h" +#import "AFHTTPSessionManager.h" @interface AFNetworkActivityManagerTests : AFTestCase @property (nonatomic, strong) AFNetworkActivityIndicatorManager *networkActivityIndicatorManager; -@property (nonatomic, assign) BOOL isNetworkActivityIndicatorVisible; -@property (nonatomic, strong) id mockApplication; +@property (nonatomic, strong) AFHTTPSessionManager *sessionManager; @end #pragma mark - @@ -37,71 +36,63 @@ @implementation AFNetworkActivityManagerTests - (void)setUp { [super setUp]; + self.sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:self.baseURL sessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]]; + self.networkActivityIndicatorManager = [[AFNetworkActivityIndicatorManager alloc] init]; self.networkActivityIndicatorManager.enabled = YES; - - self.mockApplication = [OCMockObject mockForClass:[UIApplication class]]; - [[[self.mockApplication stub] andReturn:self.mockApplication] sharedApplication]; - - [[[self.mockApplication stub] andDo:^(NSInvocation *invocation) { - [invocation setReturnValue:(void *)&_isNetworkActivityIndicatorVisible]; - }] isNetworkActivityIndicatorVisible]; - - [[[self.mockApplication stub] andDo:^(NSInvocation *invocation) { - [invocation getArgument:&_isNetworkActivityIndicatorVisible atIndex:2]; - }] setNetworkActivityIndicatorVisible:YES]; } - (void)tearDown { [super tearDown]; - [self.mockApplication stopMocking]; - - self.mockApplication = nil; self.networkActivityIndicatorManager = nil; + + [self.sessionManager invalidateSessionCancelingTasks:YES]; } #pragma mark - - (void)testThatNetworkActivityIndicatorTurnsOffIndicatorWhenRequestSucceeds { - NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/get" relativeToURL:self.baseURL]]; - AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; - [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { - expect([self.mockApplication isNetworkActivityIndicatorVisible]).will.beFalsy(); - } failure:nil]; - - [operation start]; - - expect([self.mockApplication isNetworkActivityIndicatorVisible]).will.beTruthy(); + XCTestExpectation *requestCompleteExpectation = [self expectationWithDescription:@"Request should succeed"]; + [self.sessionManager + GET:@"/delay/1" + parameters:nil + success:^(NSURLSessionDataTask * _Nonnull task, id _Nonnull responseObject) { + [requestCompleteExpectation fulfill]; + } + failure:nil]; + [self expectationForPredicate:[NSPredicate predicateWithFormat:@"isNetworkActivityIndicatorVisible == YES"] + evaluatedWithObject:self.networkActivityIndicatorManager + handler:nil]; + [self waitForExpectationsWithTimeout:10.0 handler:nil]; + + [self expectationForPredicate:[NSPredicate predicateWithFormat:@"isNetworkActivityIndicatorVisible == NO"] + evaluatedWithObject:self.networkActivityIndicatorManager + handler:nil]; + [self waitForExpectationsWithTimeout:5.0 handler:nil]; } - (void)testThatNetworkActivityIndicatorTurnsOffIndicatorWhenRequestFails { - NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/status/500" relativeToURL:self.baseURL]]; - AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; - [operation setCompletionBlockWithSuccess:nil failure:^(AFHTTPRequestOperation *operation, NSError *error) { - expect([self.mockApplication isNetworkActivityIndicatorVisible]).will.beFalsy(); - }]; - - [operation start]; - - expect([self.mockApplication isNetworkActivityIndicatorVisible]).will.beTruthy(); -} - -- (void)testThatNetworkActivityIsUnchangedWhenManagerIsDisabled { - self.networkActivityIndicatorManager.enabled = NO; - - __block BOOL didChangeNetworkActivityIndicatorVisible = NO; - - [[[self.mockApplication stub] andDo:^(NSInvocation *invocation) { - didChangeNetworkActivityIndicatorVisible = YES; - }] setNetworkActivityIndicatorVisible:YES]; - - NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"/get" relativeToURL:self.baseURL]]; - AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; - [operation setCompletionBlockWithSuccess:nil failure:nil]; - - [operation start]; - - expect(didChangeNetworkActivityIndicatorVisible).will.beFalsy(); + XCTestExpectation *requestCompleteExpectation = [self expectationWithDescription:@"Request should succeed"]; + [self.sessionManager + GET:@"/status/500" + parameters:nil + success:nil + failure:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) { + [requestCompleteExpectation fulfill]; + }]; + + [self + keyValueObservingExpectationForObject:self.networkActivityIndicatorManager + keyPath:@"isNetworkActivityIndicatorVisible" + handler:^BOOL(AFNetworkActivityIndicatorManager * observedObject, NSDictionary * _Nonnull change) { + return observedObject.isNetworkActivityIndicatorVisible; + }]; + [self waitForExpectationsWithTimeout:5.0 handler:nil]; + + [self expectationForPredicate:[NSPredicate predicateWithFormat:@"isNetworkActivityIndicatorVisible == NO"] + evaluatedWithObject:self.networkActivityIndicatorManager + handler:nil]; + [self waitForExpectationsWithTimeout:5.0 handler:nil]; } @end From 2ab3bbdcc86ac073b2fb122aba68c0293f254409 Mon Sep 17 00:00:00 2001 From: Andrey Mikhaylov Date: Mon, 12 Oct 2015 16:42:48 +0200 Subject: [PATCH 05/40] Fix linker issues when C++ imports AFNetworkReachabilityManager.h (Fixes #3040) Replace `extern` with `FOUNDATION_EXPORT` which works correctly when C++ imports the header. --- AFNetworking/AFNetworkReachabilityManager.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFNetworkReachabilityManager.h b/AFNetworking/AFNetworkReachabilityManager.h index 5a445075e0..e2eb945df0 100644 --- a/AFNetworking/AFNetworkReachabilityManager.h +++ b/AFNetworking/AFNetworkReachabilityManager.h @@ -191,8 +191,8 @@ NS_ASSUME_NONNULL_BEGIN @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`). */ -extern NSString * const AFNetworkingReachabilityDidChangeNotification; -extern NSString * const AFNetworkingReachabilityNotificationStatusItem; +FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityDidChangeNotification; +FOUNDATION_EXPORT NSString * const AFNetworkingReachabilityNotificationStatusItem; ///-------------------- /// @name Functions @@ -201,7 +201,7 @@ extern NSString * const AFNetworkingReachabilityNotificationStatusItem; /** Returns a localized string representation of an `AFNetworkReachabilityStatus` value. */ -extern NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status); +FOUNDATION_EXPORT NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status); NS_ASSUME_NONNULL_END #endif From abd9c02e9f420c932175c821d23900ae8b377b0e Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 13 Oct 2015 09:13:21 -0500 Subject: [PATCH 06/40] Migrated to FOUNDATION_EXPORT in all header files --- AFNetworking/AFURLConnectionOperation.h | 4 +-- AFNetworking/AFURLRequestSerialization.h | 8 +++--- AFNetworking/AFURLRequestSerialization.m | 4 +-- AFNetworking/AFURLResponseSerialization.h | 6 ++-- AFNetworking/AFURLSessionManager.h | 34 +++++++++++------------ 5 files changed, 28 insertions(+), 28 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.h b/AFNetworking/AFURLConnectionOperation.h index c71bed4e94..c21119e2ba 100644 --- a/AFNetworking/AFURLConnectionOperation.h +++ b/AFNetworking/AFURLConnectionOperation.h @@ -334,11 +334,11 @@ NS_ASSUME_NONNULL_BEGIN /** Posted when an operation begins executing. */ -extern NSString * const AFNetworkingOperationDidStartNotification; +FOUNDATION_EXPORT NSString * const AFNetworkingOperationDidStartNotification; /** Posted when an operation finishes. */ -extern NSString * const AFNetworkingOperationDidFinishNotification; +FOUNDATION_EXPORT NSString * const AFNetworkingOperationDidFinishNotification; NS_ASSUME_NONNULL_END diff --git a/AFNetworking/AFURLRequestSerialization.h b/AFNetworking/AFURLRequestSerialization.h index 513334b4be..ef4d3661bd 100644 --- a/AFNetworking/AFURLRequestSerialization.h +++ b/AFNetworking/AFURLRequestSerialization.h @@ -438,7 +438,7 @@ forHTTPHeaderField:(NSString *)field; `AFURLRequestSerializationErrorDomain` AFURLRequestSerializer errors. Error codes for `AFURLRequestSerializationErrorDomain` correspond to codes in `NSURLErrorDomain`. */ -extern NSString * const AFURLRequestSerializationErrorDomain; +FOUNDATION_EXPORT NSString * const AFURLRequestSerializationErrorDomain; /** ## User info dictionary keys @@ -452,7 +452,7 @@ extern NSString * const AFURLRequestSerializationErrorDomain; `AFNetworkingOperationFailingURLRequestErrorKey` The corresponding value is an `NSURLRequest` containing the request of the operation associated with an error. This key is only present in the `AFURLRequestSerializationErrorDomain`. */ -extern NSString * const AFNetworkingOperationFailingURLRequestErrorKey; +FOUNDATION_EXPORT NSString * const AFNetworkingOperationFailingURLRequestErrorKey; /** ## Throttling Bandwidth for HTTP Request Input Streams @@ -467,7 +467,7 @@ extern NSString * const AFNetworkingOperationFailingURLRequestErrorKey; `kAFUploadStream3GSuggestedDelay` Duration of delay each time a packet is read. Equal to 0.2 seconds. */ -extern NSUInteger const kAFUploadStream3GSuggestedPacketSize; -extern NSTimeInterval const kAFUploadStream3GSuggestedDelay; +FOUNDATION_EXPORT NSUInteger const kAFUploadStream3GSuggestedPacketSize; +FOUNDATION_EXPORT NSTimeInterval const kAFUploadStream3GSuggestedDelay; NS_ASSUME_NONNULL_END diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index 21bb5e0648..1f6e8380f3 100644 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -120,8 +120,8 @@ - (NSString *)URLEncodedStringValue { #pragma mark - -extern NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary); -extern NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value); +FOUNDATION_EXPORT NSArray * AFQueryStringPairsFromDictionary(NSDictionary *dictionary); +FOUNDATION_EXPORT NSArray * AFQueryStringPairsFromKeyAndValue(NSString *key, id value); static NSString * AFQueryStringFromParameters(NSDictionary *parameters) { NSMutableArray *mutablePairs = [NSMutableArray array]; diff --git a/AFNetworking/AFURLResponseSerialization.h b/AFNetworking/AFURLResponseSerialization.h index e14dc8a9d7..1396cfbd11 100644 --- a/AFNetworking/AFURLResponseSerialization.h +++ b/AFNetworking/AFURLResponseSerialization.h @@ -286,7 +286,7 @@ NS_ASSUME_NONNULL_BEGIN `AFURLResponseSerializationErrorDomain` AFURLResponseSerializer errors. Error codes for `AFURLResponseSerializationErrorDomain` correspond to codes in `NSURLErrorDomain`. */ -extern NSString * const AFURLResponseSerializationErrorDomain; +FOUNDATION_EXPORT NSString * const AFURLResponseSerializationErrorDomain; /** ## User info dictionary keys @@ -304,8 +304,8 @@ extern NSString * const AFURLResponseSerializationErrorDomain; `AFNetworkingOperationFailingURLResponseDataErrorKey` The corresponding value is an `NSData` containing the original data of the operation associated with an error. This key is only present in the `AFURLResponseSerializationErrorDomain`. */ -extern NSString * const AFNetworkingOperationFailingURLResponseErrorKey; +FOUNDATION_EXPORT NSString * const AFNetworkingOperationFailingURLResponseErrorKey; -extern NSString * const AFNetworkingOperationFailingURLResponseDataErrorKey; +FOUNDATION_EXPORT NSString * const AFNetworkingOperationFailingURLResponseDataErrorKey; NS_ASSUME_NONNULL_END diff --git a/AFNetworking/AFURLSessionManager.h b/AFNetworking/AFURLSessionManager.h index a718d964c1..70e4ec9417 100644 --- a/AFNetworking/AFURLSessionManager.h +++ b/AFNetworking/AFURLSessionManager.h @@ -457,98 +457,98 @@ NS_ASSUME_NONNULL_BEGIN @deprecated Use `AFNetworkingTaskDidResumeNotification` instead. */ -extern NSString * const AFNetworkingTaskDidStartNotification DEPRECATED_ATTRIBUTE; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidStartNotification DEPRECATED_ATTRIBUTE; /** Posted when a task resumes. */ -extern NSString * const AFNetworkingTaskDidResumeNotification; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidResumeNotification; /** Posted when a task finishes executing. Includes a userInfo dictionary with additional information about the task. @deprecated Use `AFNetworkingTaskDidCompleteNotification` instead. */ -extern NSString * const AFNetworkingTaskDidFinishNotification DEPRECATED_ATTRIBUTE; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidFinishNotification DEPRECATED_ATTRIBUTE; /** Posted when a task finishes executing. Includes a userInfo dictionary with additional information about the task. */ -extern NSString * const AFNetworkingTaskDidCompleteNotification; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidCompleteNotification; /** Posted when a task suspends its execution. */ -extern NSString * const AFNetworkingTaskDidSuspendNotification; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidSuspendNotification; /** Posted when a session is invalidated. */ -extern NSString * const AFURLSessionDidInvalidateNotification; +FOUNDATION_EXPORT NSString * const AFURLSessionDidInvalidateNotification; /** Posted when a session download task encountered an error when moving the temporary download file to a specified destination. */ -extern NSString * const AFURLSessionDownloadTaskDidFailToMoveFileNotification; +FOUNDATION_EXPORT NSString * const AFURLSessionDownloadTaskDidFailToMoveFileNotification; /** The raw response data of the task. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if response data exists for the task. @deprecated Use `AFNetworkingTaskDidCompleteResponseDataKey` instead. */ -extern NSString * const AFNetworkingTaskDidFinishResponseDataKey DEPRECATED_ATTRIBUTE; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidFinishResponseDataKey DEPRECATED_ATTRIBUTE; /** The raw response data of the task. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if response data exists for the task. */ -extern NSString * const AFNetworkingTaskDidCompleteResponseDataKey; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidCompleteResponseDataKey; /** The serialized response object of the task. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if the response was serialized. @deprecated Use `AFNetworkingTaskDidCompleteSerializedResponseKey` instead. */ -extern NSString * const AFNetworkingTaskDidFinishSerializedResponseKey DEPRECATED_ATTRIBUTE; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidFinishSerializedResponseKey DEPRECATED_ATTRIBUTE; /** The serialized response object of the task. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if the response was serialized. */ -extern NSString * const AFNetworkingTaskDidCompleteSerializedResponseKey; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidCompleteSerializedResponseKey; /** The response serializer used to serialize the response. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if the task has an associated response serializer. @deprecated Use `AFNetworkingTaskDidCompleteResponseSerializerKey` instead. */ -extern NSString * const AFNetworkingTaskDidFinishResponseSerializerKey DEPRECATED_ATTRIBUTE; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidFinishResponseSerializerKey DEPRECATED_ATTRIBUTE; /** The response serializer used to serialize the response. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if the task has an associated response serializer. */ -extern NSString * const AFNetworkingTaskDidCompleteResponseSerializerKey; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidCompleteResponseSerializerKey; /** The file path associated with the download task. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if an the response data has been stored directly to disk. @deprecated Use `AFNetworkingTaskDidCompleteAssetPathKey` instead. */ -extern NSString * const AFNetworkingTaskDidFinishAssetPathKey DEPRECATED_ATTRIBUTE; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidFinishAssetPathKey DEPRECATED_ATTRIBUTE; /** The file path associated with the download task. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if an the response data has been stored directly to disk. */ -extern NSString * const AFNetworkingTaskDidCompleteAssetPathKey; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidCompleteAssetPathKey; /** Any error associated with the task, or the serialization of the response. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if an error exists. @deprecated Use `AFNetworkingTaskDidCompleteErrorKey` instead. */ -extern NSString * const AFNetworkingTaskDidFinishErrorKey DEPRECATED_ATTRIBUTE; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidFinishErrorKey DEPRECATED_ATTRIBUTE; /** Any error associated with the task, or the serialization of the response. Included in the userInfo dictionary of the `AFNetworkingTaskDidFinishNotification` if an error exists. */ -extern NSString * const AFNetworkingTaskDidCompleteErrorKey; +FOUNDATION_EXPORT NSString * const AFNetworkingTaskDidCompleteErrorKey; NS_ASSUME_NONNULL_END From 588f2f19f2d165698a99ac537e1f0498715d456e Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Mon, 12 Oct 2015 12:09:09 -0500 Subject: [PATCH 07/40] Potential fix for #2743 --- AFNetworking/AFURLSessionManager.m | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/AFNetworking/AFURLSessionManager.m b/AFNetworking/AFURLSessionManager.m index a795a0717a..eb289591b6 100644 --- a/AFNetworking/AFURLSessionManager.m +++ b/AFNetworking/AFURLSessionManager.m @@ -328,7 +328,7 @@ + (void)load { #pragma GCC diagnostic ignored "-Wnonnull" NSURLSessionDataTask *localDataTask = [[NSURLSession sessionWithConfiguration:nil] dataTaskWithURL:nil]; #pragma clang diagnostic pop - IMP originalAFResumeIMP = method_getImplementation(class_getInstanceMethod([_AFURLSessionTaskSwizzling class], @selector(af_resume))); + IMP originalAFResumeIMP = method_getImplementation(class_getInstanceMethod([self class], @selector(af_resume))); Class currentClass = [localDataTask class]; while (class_getInstanceMethod(currentClass, @selector(resume))) { @@ -349,12 +349,14 @@ + (void)load { + (void)swizzleResumeAndSuspendMethodForClass:(Class)class { Method afResumeMethod = class_getInstanceMethod(self, @selector(af_resume)); Method afSuspendMethod = class_getInstanceMethod(self, @selector(af_suspend)); - - af_addMethod(class, @selector(af_resume), afResumeMethod); - af_addMethod(class, @selector(af_suspend), afSuspendMethod); - - af_swizzleSelector(class, @selector(resume), @selector(af_resume)); - af_swizzleSelector(class, @selector(suspend), @selector(af_suspend)); + + if (af_addMethod(class, @selector(af_resume), afResumeMethod)) { + af_swizzleSelector(class, @selector(resume), @selector(af_resume)); + } + + if (af_addMethod(class, @selector(af_suspend), afSuspendMethod)) { + af_swizzleSelector(class, @selector(suspend), @selector(af_suspend)); + } } - (NSURLSessionTaskState)state { From 4696469eaa6d695e7e87098f335348a1e91694fa Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 13 Oct 2015 12:57:33 -0500 Subject: [PATCH 08/40] Bringing in fix for #2496 --- AFNetworking/AFURLConnectionOperation.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index d28d69a3ac..0568005edd 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -669,11 +669,11 @@ - (void)connection:(NSURLConnection __unused *)connection } break; - } - - if (self.outputStream.streamError) { + } else { [self.connection cancel]; - [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.outputStream.streamError]; + if (self.outputStream.streamError) { + [self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.outputStream.streamError]; + } return; } } From a7820d2e0aff89fe0b293db5f0ae5ed11a167ea7 Mon Sep 17 00:00:00 2001 From: AM Date: Wed, 7 Oct 2015 16:11:41 +0300 Subject: [PATCH 09/40] crash fix with iOS 7 stringByAddingPercentEncodingWithAllowedCharacters method --- AFNetworking/AFURLRequestSerialization.m | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index 1f6e8380f3..d3eebb6e73 100644 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -80,7 +80,25 @@ NSMutableCharacterSet * allowedCharacterSet = [[NSCharacterSet URLQueryAllowedCharacterSet] mutableCopy]; [allowedCharacterSet removeCharactersInString:[kAFCharactersGeneralDelimitersToEncode stringByAppendingString:kAFCharactersSubDelimitersToEncode]]; - return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet]; + // FIXME: WAIT 4 APL 2 FIX DIS SHIT + //return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet]; + + static NSUInteger const batchSize = 50; + + NSInteger index = 0; + NSMutableString *escaped = @"".mutableCopy; + + while (index < string.length) { + NSUInteger length = MIN(string.length - index, batchSize); + NSRange range = NSMakeRange(index, length); + + NSString *substring = [string substringWithRange:range]; + [escaped appendString:[substring stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet]]; + + index += length; + } + + return escaped; } #pragma mark - From 6b6d41d99202c9d5986a5f8a65cd88bdfa486248 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 13 Oct 2015 13:29:42 -0500 Subject: [PATCH 10/40] - Updated implementation for #3028 - Added test demonstrating fix --- AFNetworking/AFURLRequestSerialization.m | 28 +++++++++++-------- Tests/Tests/AFHTTPRequestSerializationTests.m | 18 ++++++++++++ 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index d3eebb6e73..e387c24178 100644 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -80,23 +80,27 @@ NSMutableCharacterSet * allowedCharacterSet = [[NSCharacterSet URLQueryAllowedCharacterSet] mutableCopy]; [allowedCharacterSet removeCharactersInString:[kAFCharactersGeneralDelimitersToEncode stringByAppendingString:kAFCharactersSubDelimitersToEncode]]; - // FIXME: WAIT 4 APL 2 FIX DIS SHIT - //return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet]; + // FIXME: https://github.com/AFNetworking/AFNetworking/pull/3028 + // return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet]; - static NSUInteger const batchSize = 50; + static NSUInteger const batchSize = 50; - NSInteger index = 0; - NSMutableString *escaped = @"".mutableCopy; + NSInteger index = 0; + NSMutableString *escaped = @"".mutableCopy; - while (index < string.length) { - NSUInteger length = MIN(string.length - index, batchSize); - NSRange range = NSMakeRange(index, length); + while (index < string.length) { + NSUInteger length = MIN(string.length - index, batchSize); + NSRange range = NSMakeRange(index, length); - NSString *substring = [string substringWithRange:range]; - [escaped appendString:[substring stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet]]; + // To avoid breaking up character sequences such as 👴🏻👮🏽 + range = [string rangeOfComposedCharacterSequencesForRange:range]; - index += length; - } + NSString *substring = [string substringWithRange:range]; + NSString *encoded = [substring stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet]; + [escaped appendString:encoded]; + + index += range.length; + } return escaped; } diff --git a/Tests/Tests/AFHTTPRequestSerializationTests.m b/Tests/Tests/AFHTTPRequestSerializationTests.m index b898357b5b..0fd29e8e99 100644 --- a/Tests/Tests/AFHTTPRequestSerializationTests.m +++ b/Tests/Tests/AFHTTPRequestSerializationTests.m @@ -176,4 +176,22 @@ - (void)testQueryStringSerializationCanFailWithError { expect(error).to.equal(serializerError); } +#pragma mark - #3028 tests +//https://github.com/AFNetworking/AFNetworking/pull/3028 + +- (void)testThatEmojiIsProperlyEncoded { + //Start with an odd number of characters so we can cross the 50 character boundry + NSMutableString *parameter = [NSMutableString stringWithString:@"!"]; + while (parameter.length < 50) { + [parameter appendString:@"👴🏿👷🏻👮🏽"]; + } + + AFHTTPRequestSerializer *serializer = [AFHTTPRequestSerializer serializer]; + NSURLRequest *request = [serializer requestWithMethod:@"GET" + URLString:@"http://test.com" + parameters:@{@"test":parameter} + error:nil]; + XCTAssertTrue([request.URL.query isEqualToString:@"test=%21%F0%9F%91%B4%F0%9F%8F%BF%F0%9F%91%B7%F0%9F%8F%BB%F0%9F%91%AE%F0%9F%8F%BD%F0%9F%91%B4%F0%9F%8F%BF%F0%9F%91%B7%F0%9F%8F%BB%F0%9F%91%AE%F0%9F%8F%BD%F0%9F%91%B4%F0%9F%8F%BF%F0%9F%91%B7%F0%9F%8F%BB%F0%9F%91%AE%F0%9F%8F%BD%F0%9F%91%B4%F0%9F%8F%BF%F0%9F%91%B7%F0%9F%8F%BB%F0%9F%91%AE%F0%9F%8F%BD%F0%9F%91%B4%F0%9F%8F%BF%F0%9F%91%B7%F0%9F%8F%BB%F0%9F%91%AE%F0%9F%8F%BD"]); +} + @end From dad1b8bfcc6962915332285f74399a33e1f375dd Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 13 Oct 2015 11:02:00 -0500 Subject: [PATCH 11/40] updated docs for 2.6.1 --- AFNetworking.podspec | 2 +- CHANGELOG.md | 28 ++++++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index 66204cf67e..363a815be0 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'AFNetworking' - s.version = '2.6.0' + s.version = '2.6.1' s.license = 'MIT' s.summary = 'A delightful iOS and OS X networking framework.' s.homepage = 'https://github.com/AFNetworking/AFNetworking' diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a34799fff..3d095a7fbd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,34 @@ All notable changes to this project will be documented in this file. --- +## [2.6.1](https://github.com/AFNetworking/AFNetworking/releases/tag/2.6.1) (10-13-2015) +Released on Tuesday, October 13th, 2015. All issues associated with this milestone can be found using this [filter](https://github.com/AFNetworking/AFNetworking/issues?q=milestone%3A2.6.1+is%3Aclosed). + +###Future Compatibility Note +Note that AFNetworking 3.0 will soon be released, and will drop support for all `NSURLConnection` based API's (`AFHTTPRequestOperationManager`, `AFHTTPRequestOperation`, and `AFURLConnectionOperation`. If you have not already migrated to `NSURLSession` based API's, please do so soon. For more information, please see the [3.0 migration guide](https://github.com/AFNetworking/AFNetworking/wiki/AFNetworking-3.0-Migration-Guide). + +####Fixed +* Fixed a bug that prevented empty x-www-form-urlencoded bodies. + * Fixed by [Julien Cayzac](https://github.com/jcayzac) in [#2868](https://github.com/AFNetworking/AFNetworking/pull/2868). +* Fixed bug that prevented AFNetworking from being installed for watchOS via Cocoapods. + * Fixed by [Kevin Harwood](https://github.com/kcharwood) in [#2909](https://github.com/AFNetworking/AFNetworking/issues/2909). +* Added missing nullable attributes to `AFURLRequestSerialization` and `AFURLSessionManager`. + * Fixed by [andrewtoth](https://github.com/andrewtoth) in [#2911](https://github.com/AFNetworking/AFNetworking/pull/2911). +* Migrated to `OS_OBJECT_USE_OBJC`. + * Fixed by [canius](https://github.com/canius) in [#2930](https://github.com/AFNetworking/AFNetworking/pull/2930). +* Added missing nullable tags to UIKit extensions. + * Fixed by [Kevin Harwood](https://github.com/kcharwood) in [#3000](https://github.com/AFNetworking/AFNetworking/pull/3000). +* Fixed potential infinite recursion loop if multiple versions of AFNetworking are loaded in a target. + * Fixed by [Kevin Harwood](https://github.com/kcharwood) in [#2743](https://github.com/AFNetworking/AFNetworking/issues/2743). +* Updated Travis CI test script + * Fixed by [Kevin Harwood](https://github.com/kcharwood) in [#3032](https://github.com/AFNetworking/AFNetworking/issues/3032). +* Migrated to `FOUNDATION_EXPORT` from `extern`. + * Fixed by [Andrey Mikhaylov](https://github.com/pronebird) in [#3041](https://github.com/AFNetworking/AFNetworking/pull/3041). +* Fixed issue where `AFURLConnectionOperation` could get stuck in an infinite loop. + * Fixed by [Mattt Thompson](https://github.com/mattt) in [#2496](https://github.com/AFNetworking/AFNetworking/pull/2496). +* Fixed regression where URL request serialization would crash on iOS 8 for long URLs. + * Fixed by [softenhard](https://github.com/softenhard) in [#3028](https://github.com/AFNetworking/AFNetworking/pull/3028). + ## [2.6.0](https://github.com/AFNetworking/AFNetworking/releases/tag/2.6.0) (08-19-2015) Released on Wednesday, August 19th, 2015. All issues associated with this milestone can be found using this [filter](https://github.com/AFNetworking/AFNetworking/issues?q=milestone%3A2.6.0+is%3Aclosed). From 02b80938ee1502f210cdf754139aa0054106a15f Mon Sep 17 00:00:00 2001 From: Kyle Fuller Date: Thu, 15 Oct 2015 20:47:19 -0700 Subject: [PATCH 12/40] Switch to OS_OBJECT_USE_OBJC --- AFNetworking/AFHTTPRequestOperationManager.h | 4 ++-- AFNetworking/AFURLSessionManager.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperationManager.h b/AFNetworking/AFHTTPRequestOperationManager.h index d2385edc97..a51b492c49 100644 --- a/AFNetworking/AFHTTPRequestOperationManager.h +++ b/AFNetworking/AFHTTPRequestOperationManager.h @@ -160,7 +160,7 @@ NS_ASSUME_NONNULL_BEGIN /** The dispatch queue for the `completionBlock` of request operations. If `NULL` (default), the main queue is used. */ -#if OS_OBJECT_HAVE_OBJC_SUPPORT +#if OS_OBJECT_USE_OBJC @property (nonatomic, strong, nullable) dispatch_queue_t completionQueue; #else @property (nonatomic, assign, nullable) dispatch_queue_t completionQueue; @@ -169,7 +169,7 @@ NS_ASSUME_NONNULL_BEGIN /** The dispatch group for the `completionBlock` of request operations. If `NULL` (default), a private dispatch group is used. */ -#if OS_OBJECT_HAVE_OBJC_SUPPORT +#if OS_OBJECT_USE_OBJC @property (nonatomic, strong, nullable) dispatch_group_t completionGroup; #else @property (nonatomic, assign, nullable) dispatch_group_t completionGroup; diff --git a/AFNetworking/AFURLSessionManager.h b/AFNetworking/AFURLSessionManager.h index 70e4ec9417..f251b832b5 100644 --- a/AFNetworking/AFURLSessionManager.h +++ b/AFNetworking/AFURLSessionManager.h @@ -165,7 +165,7 @@ NS_ASSUME_NONNULL_BEGIN /** The dispatch queue for `completionBlock`. If `NULL` (default), the main queue is used. */ -#if OS_OBJECT_HAVE_OBJC_SUPPORT +#if OS_OBJECT_USE_OBJC @property (nonatomic, strong, nullable) dispatch_queue_t completionQueue; #else @property (nonatomic, assign, nullable) dispatch_queue_t completionQueue; @@ -174,7 +174,7 @@ NS_ASSUME_NONNULL_BEGIN /** The dispatch group for `completionBlock`. If `NULL` (default), a private dispatch group is used. */ -#if OS_OBJECT_HAVE_OBJC_SUPPORT +#if OS_OBJECT_USE_OBJC @property (nonatomic, strong, nullable) dispatch_group_t completionGroup; #else @property (nonatomic, assign, nullable) dispatch_group_t completionGroup; From 807f1b9c75858c54b571fe82831a915de4762765 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Mon, 19 Oct 2015 15:51:29 -0500 Subject: [PATCH 13/40] AFSecurityPolicy now conforms to NSSecureCoding and NSCopying for #2887 --- AFNetworking/AFHTTPRequestOperationManager.m | 6 +++ AFNetworking/AFHTTPSessionManager.m | 7 +++- AFNetworking/AFSecurityPolicy.h | 2 +- AFNetworking/AFSecurityPolicy.m | 40 ++++++++++++++++++++ Tests/Tests/AFSecurityPolicyTests.m | 37 ++++++++++++++++++ 5 files changed, 90 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperationManager.m b/AFNetworking/AFHTTPRequestOperationManager.m index 60739e5f0d..ee682b794e 100644 --- a/AFNetworking/AFHTTPRequestOperationManager.m +++ b/AFNetworking/AFHTTPRequestOperationManager.m @@ -260,6 +260,10 @@ - (id)initWithCoder:(NSCoder *)decoder { self.requestSerializer = [decoder decodeObjectOfClass:[AFHTTPRequestSerializer class] forKey:NSStringFromSelector(@selector(requestSerializer))]; self.responseSerializer = [decoder decodeObjectOfClass:[AFHTTPResponseSerializer class] forKey:NSStringFromSelector(@selector(responseSerializer))]; + AFSecurityPolicy *decodedPolicy = [decoder decodeObjectOfClass:[AFSecurityPolicy class] forKey:NSStringFromSelector(@selector(securityPolicy))]; + if (decodedPolicy) { + self.securityPolicy = decodedPolicy; + } return self; } @@ -268,6 +272,7 @@ - (void)encodeWithCoder:(NSCoder *)coder { [coder encodeObject:self.baseURL forKey:NSStringFromSelector(@selector(baseURL))]; [coder encodeObject:self.requestSerializer forKey:NSStringFromSelector(@selector(requestSerializer))]; [coder encodeObject:self.responseSerializer forKey:NSStringFromSelector(@selector(responseSerializer))]; + [coder encodeObject:self.securityPolicy forKey:NSStringFromSelector(@selector(securityPolicy))]; } #pragma mark - NSCopying @@ -277,6 +282,7 @@ - (id)copyWithZone:(NSZone *)zone { HTTPClient.requestSerializer = [self.requestSerializer copyWithZone:zone]; HTTPClient.responseSerializer = [self.responseSerializer copyWithZone:zone]; + HTTPClient.securityPolicy = [self.securityPolicy copyWithZone:zone]; return HTTPClient; } diff --git a/AFNetworking/AFHTTPSessionManager.m b/AFNetworking/AFHTTPSessionManager.m index bd9163faa4..ed46b26d3c 100644 --- a/AFNetworking/AFHTTPSessionManager.m +++ b/AFNetworking/AFHTTPSessionManager.m @@ -290,6 +290,10 @@ - (id)initWithCoder:(NSCoder *)decoder { self.requestSerializer = [decoder decodeObjectOfClass:[AFHTTPRequestSerializer class] forKey:NSStringFromSelector(@selector(requestSerializer))]; self.responseSerializer = [decoder decodeObjectOfClass:[AFHTTPResponseSerializer class] forKey:NSStringFromSelector(@selector(responseSerializer))]; + AFSecurityPolicy *decodedPolicy = [decoder decodeObjectOfClass:[AFSecurityPolicy class] forKey:NSStringFromSelector(@selector(securityPolicy))]; + if (decodedPolicy) { + self.securityPolicy = decodedPolicy; + } return self; } @@ -305,6 +309,7 @@ - (void)encodeWithCoder:(NSCoder *)coder { } [coder encodeObject:self.requestSerializer forKey:NSStringFromSelector(@selector(requestSerializer))]; [coder encodeObject:self.responseSerializer forKey:NSStringFromSelector(@selector(responseSerializer))]; + [coder encodeObject:self.securityPolicy forKey:NSStringFromSelector(@selector(securityPolicy))]; } #pragma mark - NSCopying @@ -314,7 +319,7 @@ - (id)copyWithZone:(NSZone *)zone { HTTPClient.requestSerializer = [self.requestSerializer copyWithZone:zone]; HTTPClient.responseSerializer = [self.responseSerializer copyWithZone:zone]; - + HTTPClient.securityPolicy = [self.securityPolicy copyWithZone:zone]; return HTTPClient; } diff --git a/AFNetworking/AFSecurityPolicy.h b/AFNetworking/AFSecurityPolicy.h index 3c38da8307..d968f49d09 100644 --- a/AFNetworking/AFSecurityPolicy.h +++ b/AFNetworking/AFSecurityPolicy.h @@ -36,7 +36,7 @@ typedef NS_ENUM(NSUInteger, AFSSLPinningMode) { NS_ASSUME_NONNULL_BEGIN -@interface AFSecurityPolicy : NSObject +@interface AFSecurityPolicy : NSObject /** The criteria by which server trust should be evaluated against the pinned SSL certificates. Defaults to `AFSSLPinningModeNone`. diff --git a/AFNetworking/AFSecurityPolicy.m b/AFNetworking/AFSecurityPolicy.m index e8eaa65f11..70b56392c4 100644 --- a/AFNetworking/AFSecurityPolicy.m +++ b/AFNetworking/AFSecurityPolicy.m @@ -308,4 +308,44 @@ + (NSSet *)keyPathsForValuesAffectingPinnedPublicKeys { return [NSSet setWithObject:@"pinnedCertificates"]; } +#pragma mark - NSSecureCoding + ++ (BOOL)supportsSecureCoding { + return YES; +} + +- (id)initWithCoder:(NSCoder *)decoder { + + self = [self init]; + if (!self) { + return nil; + } + + self.SSLPinningMode = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(SSLPinningMode))] unsignedIntegerValue]; + self.allowInvalidCertificates = [decoder decodeBoolForKey:NSStringFromSelector(@selector(allowInvalidCertificates))]; + self.validatesDomainName = [decoder decodeBoolForKey:NSStringFromSelector(@selector(validatesDomainName))]; + self.pinnedCertificates = [decoder decodeObjectOfClass:[NSArray class] forKey:NSStringFromSelector(@selector(pinnedCertificates))]; + + return self; +} + +- (void)encodeWithCoder:(NSCoder *)coder { + [coder encodeObject:[NSNumber numberWithUnsignedInteger:self.SSLPinningMode] forKey:NSStringFromSelector(@selector(SSLPinningMode))]; + [coder encodeBool:self.allowInvalidCertificates forKey:NSStringFromSelector(@selector(allowInvalidCertificates))]; + [coder encodeBool:self.validatesDomainName forKey:NSStringFromSelector(@selector(validatesDomainName))]; + [coder encodeObject:self.pinnedCertificates forKey:NSStringFromSelector(@selector(pinnedCertificates))]; +} + +#pragma mark - NSCopying + +- (instancetype)copyWithZone:(NSZone *)zone { + AFSecurityPolicy *securityPolicy = [[[self class] allocWithZone:zone] init]; + securityPolicy.SSLPinningMode = self.SSLPinningMode; + securityPolicy.allowInvalidCertificates = self.allowInvalidCertificates; + securityPolicy.validatesDomainName = self.validatesDomainName; + securityPolicy.pinnedCertificates = [self.pinnedCertificates copyWithZone:zone]; + + return securityPolicy; +} + @end diff --git a/Tests/Tests/AFSecurityPolicyTests.m b/Tests/Tests/AFSecurityPolicyTests.m index e49ee823b7..21bd52b349 100644 --- a/Tests/Tests/AFSecurityPolicyTests.m +++ b/Tests/Tests/AFSecurityPolicyTests.m @@ -561,4 +561,41 @@ - (void)testThatPolicyWithInvalidCertificatesAllowedAndNoValidPinnedCertificates XCTAssertFalse([policy evaluateServerTrust:trust forDomain:@"foobar.com"], @"Policy should not allow server trust because invalid certificates are allowed but there are no pinned certificates"); } + +#pragma mark - NSCopying +- (void)testThatPolicyCanBeCopied { + AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]; + policy.allowInvalidCertificates = YES; + policy.validatesDomainName = NO; + + AFSecurityPolicy *copiedPolicy = [policy copy]; + XCTAssertNotEqual(copiedPolicy, policy); + XCTAssertEqual(copiedPolicy.allowInvalidCertificates, policy.allowInvalidCertificates); + XCTAssertEqual(copiedPolicy.validatesDomainName, policy.validatesDomainName); + XCTAssertEqual(copiedPolicy.SSLPinningMode, policy.SSLPinningMode); + XCTAssertNotEqual(copiedPolicy.pinnedCertificates, policy.pinnedCertificates); + XCTAssertTrue([copiedPolicy.pinnedCertificates isEqualToArray:policy.pinnedCertificates]); +} + +- (void)testThatPolicyCanBeEncodedAndDecoded { + AFSecurityPolicy *policy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]; + policy.allowInvalidCertificates = YES; + policy.validatesDomainName = NO; + + NSMutableData *archiveData = [NSMutableData new]; + NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:archiveData]; + [archiver encodeObject:policy forKey:@"policy"]; + [archiver finishEncoding]; + + NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:archiveData]; + AFSecurityPolicy *unarchivedPolicy = [unarchiver decodeObjectOfClass:[AFSecurityPolicy class] forKey:@"policy"]; + + XCTAssertNotEqual(unarchivedPolicy, policy); + XCTAssertEqual(unarchivedPolicy.allowInvalidCertificates, policy.allowInvalidCertificates); + XCTAssertEqual(unarchivedPolicy.validatesDomainName, policy.validatesDomainName); + XCTAssertEqual(unarchivedPolicy.SSLPinningMode, policy.SSLPinningMode); + XCTAssertNotEqual(unarchivedPolicy.pinnedCertificates, policy.pinnedCertificates); + XCTAssertTrue([unarchivedPolicy.pinnedCertificates isEqualToArray:policy.pinnedCertificates]); +} + @end From 4f3933572513a630142d35bab74adf5c7ba0ec69 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 20 Oct 2015 09:25:52 -0500 Subject: [PATCH 14/40] Changed id to instancetype --- AFNetworking/AFSecurityPolicy.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFSecurityPolicy.m b/AFNetworking/AFSecurityPolicy.m index 70b56392c4..e984b86add 100644 --- a/AFNetworking/AFSecurityPolicy.m +++ b/AFNetworking/AFSecurityPolicy.m @@ -314,7 +314,7 @@ + (BOOL)supportsSecureCoding { return YES; } -- (id)initWithCoder:(NSCoder *)decoder { +- (instancetype)initWithCoder:(NSCoder *)decoder { self = [self init]; if (!self) { From d89c4fefe7b1a8012a30365d6638e79bf1096f62 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Wed, 21 Oct 2015 08:48:21 -0500 Subject: [PATCH 15/40] Cherry-picked change from #3063 --- AFNetworking/AFSecurityPolicy.m | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/AFNetworking/AFSecurityPolicy.m b/AFNetworking/AFSecurityPolicy.m index e984b86add..2624775605 100644 --- a/AFNetworking/AFSecurityPolicy.m +++ b/AFNetworking/AFSecurityPolicy.m @@ -251,11 +251,7 @@ - (BOOL)evaluateServerTrust:(SecTrustRef)serverTrust SecTrustSetPolicies(serverTrust, (__bridge CFArrayRef)policies); if (self.SSLPinningMode == AFSSLPinningModeNone) { - if (self.allowInvalidCertificates || AFServerTrustIsValid(serverTrust)){ - return YES; - } else { - return NO; - } + return self.allowInvalidCertificates || AFServerTrustIsValid(serverTrust); } else if (!AFServerTrustIsValid(serverTrust) && !self.allowInvalidCertificates) { return NO; } From 76bc4cb3f48594ca4a15047c19591cad09a5a90f Mon Sep 17 00:00:00 2001 From: Takeru Chuganji Date: Wed, 14 Oct 2015 18:16:58 +0900 Subject: [PATCH 16/40] add missing __nullable attributes --- AFNetworking/AFHTTPRequestOperationManager.h | 16 ++++++++-------- AFNetworking/AFHTTPSessionManager.h | 14 +++++++------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/AFNetworking/AFHTTPRequestOperationManager.h b/AFNetworking/AFHTTPRequestOperationManager.h index a51b492c49..c11aeca9a5 100644 --- a/AFNetworking/AFHTTPRequestOperationManager.h +++ b/AFNetworking/AFHTTPRequestOperationManager.h @@ -208,7 +208,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success - failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; ///--------------------------- /// @name Making HTTP Requests @@ -227,7 +227,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable AFHTTPRequestOperation *)GET:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success - failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; /** Creates and runs an `AFHTTPRequestOperation` with a `HEAD` request. @@ -242,7 +242,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable AFHTTPRequestOperation *)HEAD:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(AFHTTPRequestOperation *operation))success - failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; /** Creates and runs an `AFHTTPRequestOperation` with a `POST` request. @@ -257,7 +257,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable AFHTTPRequestOperation *)POST:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success - failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; /** Creates and runs an `AFHTTPRequestOperation` with a multipart `POST` request. @@ -274,7 +274,7 @@ NS_ASSUME_NONNULL_BEGIN parameters:(nullable id)parameters constructingBodyWithBlock:(nullable void (^)(id formData))block success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success - failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; /** Creates and runs an `AFHTTPRequestOperation` with a `PUT` request. @@ -289,7 +289,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable AFHTTPRequestOperation *)PUT:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success - failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; /** Creates and runs an `AFHTTPRequestOperation` with a `PATCH` request. @@ -304,7 +304,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable AFHTTPRequestOperation *)PATCH:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success - failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; /** Creates and runs an `AFHTTPRequestOperation` with a `DELETE` request. @@ -319,7 +319,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable AFHTTPRequestOperation *)DELETE:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success - failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; @end diff --git a/AFNetworking/AFHTTPSessionManager.h b/AFNetworking/AFHTTPSessionManager.h index e516e6d661..04b087626f 100644 --- a/AFNetworking/AFHTTPSessionManager.h +++ b/AFNetworking/AFHTTPSessionManager.h @@ -152,7 +152,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURLSessionDataTask *)GET:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success - failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure; + failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** Creates and runs an `NSURLSessionDataTask` with a `HEAD` request. @@ -167,7 +167,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURLSessionDataTask *)HEAD:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(NSURLSessionDataTask *task))success - failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure; + failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** Creates and runs an `NSURLSessionDataTask` with a `POST` request. @@ -182,7 +182,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURLSessionDataTask *)POST:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success - failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure; + failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** Creates and runs an `NSURLSessionDataTask` with a multipart `POST` request. @@ -199,7 +199,7 @@ NS_ASSUME_NONNULL_BEGIN parameters:(nullable id)parameters constructingBodyWithBlock:(nullable void (^)(id formData))block success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success - failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure; + failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** Creates and runs an `NSURLSessionDataTask` with a `PUT` request. @@ -214,7 +214,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURLSessionDataTask *)PUT:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success - failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure; + failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** Creates and runs an `NSURLSessionDataTask` with a `PATCH` request. @@ -229,7 +229,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURLSessionDataTask *)PATCH:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success - failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure; + failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; /** Creates and runs an `NSURLSessionDataTask` with a `DELETE` request. @@ -244,7 +244,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURLSessionDataTask *)DELETE:(NSString *)URLString parameters:(nullable id)parameters success:(nullable void (^)(NSURLSessionDataTask *task, id responseObject))success - failure:(nullable void (^)(NSURLSessionDataTask *task, NSError *error))failure; + failure:(nullable void (^)(NSURLSessionDataTask * __nullable task, NSError *error))failure; @end From 3e12404b2d1693f7bdea3ff435f2e419d5c7a531 Mon Sep 17 00:00:00 2001 From: Takeru Chuganji Date: Thu, 15 Oct 2015 23:28:07 +0900 Subject: [PATCH 17/40] fix nullablity --- AFNetworking/AFHTTPRequestOperationManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFHTTPRequestOperationManager.h b/AFNetworking/AFHTTPRequestOperationManager.h index c11aeca9a5..8170811654 100644 --- a/AFNetworking/AFHTTPRequestOperationManager.h +++ b/AFNetworking/AFHTTPRequestOperationManager.h @@ -208,7 +208,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (AFHTTPRequestOperation *)HTTPRequestOperationWithRequest:(NSURLRequest *)request success:(nullable void (^)(AFHTTPRequestOperation *operation, id responseObject))success - failure:(nullable void (^)(AFHTTPRequestOperation * __nullable operation, NSError *error))failure; + failure:(nullable void (^)(AFHTTPRequestOperation *operation, NSError *error))failure; ///--------------------------- /// @name Making HTTP Requests From c90c3dae6872d790e384b5c3b7237a3c9f440415 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Wed, 21 Oct 2015 09:25:05 -0500 Subject: [PATCH 18/40] Added test for #3057 --- Tests/Tests/AFHTTPSessionManagerTests.m | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/Tests/Tests/AFHTTPSessionManagerTests.m b/Tests/Tests/AFHTTPSessionManagerTests.m index 2f996164bc..bd2ddae5ad 100644 --- a/Tests/Tests/AFHTTPSessionManagerTests.m +++ b/Tests/Tests/AFHTTPSessionManagerTests.m @@ -139,6 +139,26 @@ - (void)testDownloadFileCompletionSpecifiesURLInCompletionBlock { expect(downloadFilePath).willNot.beNil(); } +- (void)testThatSerializationErrorGeneratesErrorAndNullTaskForGET { + XCTestExpectation *expectation = [self expectationWithDescription:@"Serialization should fail"]; + + [self.manager.requestSerializer setQueryStringSerializationWithBlock:^NSString * _Nonnull(NSURLRequest * _Nonnull request, id _Nonnull parameters, NSError * _Nullable __autoreleasing * _Nullable error) { + *error = [NSError errorWithDomain:@"Custom" code:-1 userInfo:nil]; + return @""; + }]; + + NSURLSessionTask *nilTask; + nilTask = [self.manager + GET:@"test" + parameters:@{@"key":@"value"} + success:nil + failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) { + XCTAssertNil(task); + [expectation fulfill]; + }]; + XCTAssertNil(nilTask); + [self waitForExpectationsWithTimeout:10.0 handler:nil]; +} @end From b43776acfee569d1a66c58294ad32472cecdfa54 Mon Sep 17 00:00:00 2001 From: Oleg Naumenko Date: Thu, 18 Jun 2015 18:07:20 +0300 Subject: [PATCH 19/40] fix memory leak in NSURLSession --- AFNetworking/AFURLSessionManager.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/AFNetworking/AFURLSessionManager.m b/AFNetworking/AFURLSessionManager.m index eb289591b6..06b6dd535c 100644 --- a/AFNetworking/AFURLSessionManager.m +++ b/AFNetworking/AFURLSessionManager.m @@ -324,10 +324,8 @@ + (void)load { 7) If the current class implementation of `resume` is not equal to the super class implementation of `resume` AND the current implementation of `resume` is not equal to the original implementation of `af_resume`, THEN swizzle the methods 8) Set the current class to the super class, and repeat steps 3-8 */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wnonnull" + NSURLSession * session = [NSURLSession sessionWithConfiguration:nil]; NSURLSessionDataTask *localDataTask = [[NSURLSession sessionWithConfiguration:nil] dataTaskWithURL:nil]; -#pragma clang diagnostic pop IMP originalAFResumeIMP = method_getImplementation(class_getInstanceMethod([self class], @selector(af_resume))); Class currentClass = [localDataTask class]; @@ -343,6 +341,7 @@ + (void)load { } [localDataTask cancel]; + [session finishTasksAndInvalidate]; } } From 22baaac0e090db7d73fb487aa413e1e6dce9b5ff Mon Sep 17 00:00:00 2001 From: Oleg Naumenko Date: Fri, 19 Jun 2015 00:50:17 +0300 Subject: [PATCH 20/40] fix memory leak --- AFNetworking/AFURLSessionManager.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFURLSessionManager.m b/AFNetworking/AFURLSessionManager.m index 06b6dd535c..30dbf1faf9 100644 --- a/AFNetworking/AFURLSessionManager.m +++ b/AFNetworking/AFURLSessionManager.m @@ -325,7 +325,7 @@ + (void)load { 8) Set the current class to the super class, and repeat steps 3-8 */ NSURLSession * session = [NSURLSession sessionWithConfiguration:nil]; - NSURLSessionDataTask *localDataTask = [[NSURLSession sessionWithConfiguration:nil] dataTaskWithURL:nil]; + NSURLSessionDataTask *localDataTask = [session dataTaskWithURL:nil]; IMP originalAFResumeIMP = method_getImplementation(class_getInstanceMethod([self class], @selector(af_resume))); Class currentClass = [localDataTask class]; From 09f6cc19e1a52202f0121037cf0155bae91a2e0b Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Wed, 21 Oct 2015 13:55:07 -0500 Subject: [PATCH 21/40] Additional updates for #2794 --- AFNetworking/AFURLSessionManager.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFURLSessionManager.m b/AFNetworking/AFURLSessionManager.m index 30dbf1faf9..30a2022493 100644 --- a/AFNetworking/AFURLSessionManager.m +++ b/AFNetworking/AFURLSessionManager.m @@ -324,8 +324,12 @@ + (void)load { 7) If the current class implementation of `resume` is not equal to the super class implementation of `resume` AND the current implementation of `resume` is not equal to the original implementation of `af_resume`, THEN swizzle the methods 8) Set the current class to the super class, and repeat steps 3-8 */ - NSURLSession * session = [NSURLSession sessionWithConfiguration:nil]; + NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration]; + NSURLSession * session = [NSURLSession sessionWithConfiguration:configuration]; +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wnonnull" NSURLSessionDataTask *localDataTask = [session dataTaskWithURL:nil]; +#pragma clang diagnostic pop IMP originalAFResumeIMP = method_getImplementation(class_getInstanceMethod([self class], @selector(af_resume))); Class currentClass = [localDataTask class]; From 6f20bf25b1414a11cdfb6105b2730dc3cc87c0b0 Mon Sep 17 00:00:00 2001 From: Raphael Doehring Date: Mon, 26 Oct 2015 17:21:28 +0100 Subject: [PATCH 22/40] =?UTF-8?q?Fix=20README=20link=20to=20WWDC=20session?= =?UTF-8?q?=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Apple changed the format WWDC video URLs. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f25efe0890..d250fb8182 100644 --- a/README.md +++ b/README.md @@ -263,7 +263,7 @@ NSDictionary *parameters = @{@"foo": @"bar", @"baz": @[@1, @2, @3]}; * Network reachability is a useful tool for determining why a request might have failed. * After a network request has failed, telling the user they're offline is better than giving them a more technical but accurate error, such as "request timed out." -See also [WWDC 2012 session 706, "Networking Best Practices."](https://developer.apple.com/videos/wwdc/2012/#706). +See also [WWDC 2012 session 706, "Networking Best Practices."](https://developer.apple.com/videos/play/wwdc2012-706/). #### Shared Network Reachability From bb3773e20cae652939f5ab96891f927073788f85 Mon Sep 17 00:00:00 2001 From: Steve Christensen Date: Thu, 1 Oct 2015 18:16:54 -0700 Subject: [PATCH 23/40] Added some casts to fix compiler errors with stricy build settings. Renamed some function parameters to avoid reserved keyword issues if the compiler is set for Obj-C++. --- AFNetworking/AFURLConnectionOperation.m | 2 +- AFNetworking/AFURLRequestSerialization.m | 4 ++-- AFNetworking/AFURLResponseSerialization.m | 2 +- AFNetworking/AFURLSessionManager.m | 20 ++++++++++---------- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/AFNetworking/AFURLConnectionOperation.m b/AFNetworking/AFURLConnectionOperation.m index 0568005edd..2126ca6f06 100644 --- a/AFNetworking/AFURLConnectionOperation.m +++ b/AFNetworking/AFURLConnectionOperation.m @@ -743,7 +743,7 @@ - (id)initWithCoder:(NSCoder *)decoder { return nil; } - self.state = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(state))] integerValue]; + self.state = (AFOperationState)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(state))] integerValue]; self.response = [decoder decodeObjectOfClass:[NSHTTPURLResponse class] forKey:NSStringFromSelector(@selector(response))]; self.error = [decoder decodeObjectOfClass:[NSError class] forKey:NSStringFromSelector(@selector(error))]; self.responseData = [decoder decodeObjectOfClass:[NSData class] forKey:NSStringFromSelector(@selector(responseData))]; diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index e387c24178..315d365f15 100644 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -598,7 +598,7 @@ - (id)initWithCoder:(NSCoder *)decoder { } self.mutableHTTPRequestHeaders = [[decoder decodeObjectOfClass:[NSDictionary class] forKey:NSStringFromSelector(@selector(mutableHTTPRequestHeaders))] mutableCopy]; - self.queryStringSerializationStyle = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(queryStringSerializationStyle))] unsignedIntegerValue]; + self.queryStringSerializationStyle = (AFHTTPRequestQueryStringSerializationStyle)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(queryStringSerializationStyle))] unsignedIntegerValue]; return self; } @@ -1399,7 +1399,7 @@ - (id)initWithCoder:(NSCoder *)decoder { return nil; } - self.format = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(format))] unsignedIntegerValue]; + self.format = (NSPropertyListFormat)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(format))] unsignedIntegerValue]; self.writeOptions = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(writeOptions))] unsignedIntegerValue]; return self; diff --git a/AFNetworking/AFURLResponseSerialization.m b/AFNetworking/AFURLResponseSerialization.m index f95834f1dd..cfa8287a26 100644 --- a/AFNetworking/AFURLResponseSerialization.m +++ b/AFNetworking/AFURLResponseSerialization.m @@ -501,7 +501,7 @@ - (id)initWithCoder:(NSCoder *)decoder { return nil; } - self.format = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(format))] unsignedIntegerValue]; + self.format = (NSPropertyListFormat)[[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(format))] unsignedIntegerValue]; self.readOptions = [[decoder decodeObjectOfClass:[NSNumber class] forKey:NSStringFromSelector(@selector(readOptions))] unsignedIntegerValue]; return self; diff --git a/AFNetworking/AFURLSessionManager.m b/AFNetworking/AFURLSessionManager.m index 30a2022493..8ec0f0843b 100644 --- a/AFNetworking/AFURLSessionManager.m +++ b/AFNetworking/AFURLSessionManager.m @@ -272,14 +272,14 @@ - (void)URLSession:(__unused NSURLSession *)session * - https://github.com/AFNetworking/AFNetworking/pull/2702 */ -static inline void af_swizzleSelector(Class class, SEL originalSelector, SEL swizzledSelector) { - Method originalMethod = class_getInstanceMethod(class, originalSelector); - Method swizzledMethod = class_getInstanceMethod(class, swizzledSelector); +static inline void af_swizzleSelector(Class theClass, SEL originalSelector, SEL swizzledSelector) { + Method originalMethod = class_getInstanceMethod(theClass, originalSelector); + Method swizzledMethod = class_getInstanceMethod(theClass, swizzledSelector); method_exchangeImplementations(originalMethod, swizzledMethod); } -static inline BOOL af_addMethod(Class class, SEL selector, Method method) { - return class_addMethod(class, selector, method_getImplementation(method), method_getTypeEncoding(method)); +static inline BOOL af_addMethod(Class theClass, SEL selector, Method method) { + return class_addMethod(theClass, selector, method_getImplementation(method), method_getTypeEncoding(method)); } static NSString * const AFNSURLSessionTaskDidResumeNotification = @"com.alamofire.networking.nsurlsessiontask.resume"; @@ -349,16 +349,16 @@ + (void)load { } } -+ (void)swizzleResumeAndSuspendMethodForClass:(Class)class { ++ (void)swizzleResumeAndSuspendMethodForClass:(Class)theClass { Method afResumeMethod = class_getInstanceMethod(self, @selector(af_resume)); Method afSuspendMethod = class_getInstanceMethod(self, @selector(af_suspend)); - if (af_addMethod(class, @selector(af_resume), afResumeMethod)) { - af_swizzleSelector(class, @selector(resume), @selector(af_resume)); + if (af_addMethod(theClass, @selector(af_resume), afResumeMethod)) { + af_swizzleSelector(theClass, @selector(resume), @selector(af_resume)); } - if (af_addMethod(class, @selector(af_suspend), afSuspendMethod)) { - af_swizzleSelector(class, @selector(suspend), @selector(af_suspend)); + if (af_addMethod(theClass, @selector(af_suspend), afSuspendMethod)) { + af_swizzleSelector(theClass, @selector(suspend), @selector(af_suspend)); } } From 477bdee8003dc39eaad9aaf5d50f91d944f7fa42 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 27 Oct 2015 14:06:37 -0500 Subject: [PATCH 24/40] Removed additional warnings --- AFNetworking/AFURLRequestSerialization.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFURLRequestSerialization.m b/AFNetworking/AFURLRequestSerialization.m index 315d365f15..7e22454108 100644 --- a/AFNetworking/AFURLRequestSerialization.m +++ b/AFNetworking/AFURLRequestSerialization.m @@ -85,11 +85,14 @@ static NSUInteger const batchSize = 50; - NSInteger index = 0; + NSUInteger index = 0; NSMutableString *escaped = @"".mutableCopy; while (index < string.length) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wgnu" NSUInteger length = MIN(string.length - index, batchSize); +#pragma GCC diagnostic pop NSRange range = NSMakeRange(index, length); // To avoid breaking up character sequences such as 👴🏻👮🏽 From 97519e4e6bef87f62272ca1556bd212780eaa3d7 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 27 Oct 2015 14:09:57 -0500 Subject: [PATCH 25/40] Updated project settings for Xcode 7.1 --- .../AFNetworking OS X Example.xcodeproj/project.pbxproj | 7 ++++++- .../xcshareddata/xcschemes/AFNetworking Example.xcscheme | 2 +- .../xcschemes/AFNetworking iOS Example.xcscheme | 2 +- .../xcshareddata/xcschemes/AFNetworking watchOS.xcscheme | 2 +- .../xcshareddata/xcschemes/Today Extension.xcscheme | 2 +- Example/Mac-Info.plist | 2 +- .../xcshareddata/xcschemes/OS X Tests.xcscheme | 2 +- .../xcshareddata/xcschemes/iOS Tests.xcscheme | 2 +- 8 files changed, 13 insertions(+), 8 deletions(-) diff --git a/Example/AFNetworking OS X Example.xcodeproj/project.pbxproj b/Example/AFNetworking OS X Example.xcodeproj/project.pbxproj index 0d4635fbc4..fd9261b916 100644 --- a/Example/AFNetworking OS X Example.xcodeproj/project.pbxproj +++ b/Example/AFNetworking OS X Example.xcodeproj/project.pbxproj @@ -227,7 +227,7 @@ F8129BF21591061B009BFE23 /* Project object */ = { isa = PBXProject; attributes = { - LastUpgradeCheck = 0610; + LastUpgradeCheck = 0710; }; buildConfigurationList = F8129BF51591061B009BFE23 /* Build configuration list for PBXProject "AFNetworking OS X Example" */; compatibilityVersion = "Xcode 3.2"; @@ -297,9 +297,11 @@ CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; COPY_PHASE_STRIP = NO; ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", @@ -336,6 +338,7 @@ ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_NO_COMMON_BLOCKS = YES; GCC_VERSION = com.apple.compilers.llvm.clang.1_0; GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; @@ -357,6 +360,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = Prefix.pch; INFOPLIST_FILE = "Mac-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.alamofire.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -371,6 +375,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = Prefix.pch; INFOPLIST_FILE = "Mac-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.alamofire.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; diff --git a/Example/AFNetworking OS X Example.xcodeproj/xcshareddata/xcschemes/AFNetworking Example.xcscheme b/Example/AFNetworking OS X Example.xcodeproj/xcshareddata/xcschemes/AFNetworking Example.xcscheme index 6ff0d3e207..b97e123ad6 100644 --- a/Example/AFNetworking OS X Example.xcodeproj/xcshareddata/xcschemes/AFNetworking Example.xcscheme +++ b/Example/AFNetworking OS X Example.xcodeproj/xcshareddata/xcschemes/AFNetworking Example.xcscheme @@ -1,6 +1,6 @@ CFBundleIconFile CFBundleIdentifier - com.alamofire.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/OS X Tests.xcscheme b/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/OS X Tests.xcscheme index 4891d6dcbd..401f987829 100644 --- a/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/OS X Tests.xcscheme +++ b/Tests/AFNetworking Tests.xcodeproj/xcshareddata/xcschemes/OS X Tests.xcscheme @@ -1,6 +1,6 @@ Date: Tue, 27 Oct 2015 14:10:40 -0500 Subject: [PATCH 26/40] Updating Test Target for new version of Cocoapods --- .../project.pbxproj | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Tests/AFNetworking Tests.xcodeproj/project.pbxproj b/Tests/AFNetworking Tests.xcodeproj/project.pbxproj index e6136a95bf..724a1d50de 100644 --- a/Tests/AFNetworking Tests.xcodeproj/project.pbxproj +++ b/Tests/AFNetworking Tests.xcodeproj/project.pbxproj @@ -370,6 +370,7 @@ 2902D27517DF4E1100C81C5A /* Frameworks */, 2902D27617DF4E1100C81C5A /* Resources */, DFF6BB8B6C8D4F8ABC235667 /* Copy Pods Resources */, + 52EFA949F9B961EBF551E519 /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -389,6 +390,7 @@ 2902D28917DF4E2900C81C5A /* Frameworks */, 2902D28A17DF4E2900C81C5A /* Resources */, D728EB5862164B87922C9B80 /* Copy Pods Resources */, + 2EF045980BC7CC4F5DE8BA5D /* Embed Pods Frameworks */, ); buildRules = ( ); @@ -472,6 +474,36 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 2EF045980BC7CC4F5DE8BA5D /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-osx/Pods-osx-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; + 52EFA949F9B961EBF551E519 /* Embed Pods Frameworks */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + name = "Embed Pods Frameworks"; + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-ios/Pods-ios-frameworks.sh\"\n"; + showEnvVarsInLog = 0; + }; 54CD36584E3B40719F14C3C9 /* Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; From 1838e686389f212bebb65be58de5b8b3d970fda2 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Tue, 27 Oct 2015 14:16:51 -0500 Subject: [PATCH 27/40] Suppressed warnings for test file --- Tests/Tests/AFUIImageViewTests.m | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Tests/Tests/AFUIImageViewTests.m b/Tests/Tests/AFUIImageViewTests.m index 27d771c9be..8fd98f776c 100644 --- a/Tests/Tests/AFUIImageViewTests.m +++ b/Tests/Tests/AFUIImageViewTests.m @@ -59,18 +59,24 @@ - (void)tearDownSharedImageCache { - (void)testSetImageWithURLRequestUsesCachedImage { XCTestExpectation *expectation = [self expectationWithDescription:@"Image view uses cached image"]; - typeof(self) __weak weakSelf = self; + + __block NSURLRequest *responseRequest = nil; + __block UIImage *responseImage = nil; + __block NSHTTPURLResponse *urlResponse; [self.imageView setImageWithURLRequest:self.cachedImageRequest placeholderImage:nil success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) { - XCTAssertEqual(request, weakSelf.cachedImageRequest, @"URL requests do not match"); - XCTAssertNil(response, @"Response should be nil when image is returned from cache"); - XCTAssertEqual(image, weakSelf.cachedImage, @"Cached images do not match"); + responseRequest = request; + responseImage = image; + urlResponse = response; [expectation fulfill]; } failure:nil]; [self waitForExpectationsWithTimeout:5.0 handler:nil]; + XCTAssertEqual(responseRequest, self.cachedImageRequest, @"URL requests do not match"); + XCTAssertNil(urlResponse, @"Response should be nil when image is returned from cache"); + XCTAssertEqual(responseImage, self.cachedImage, @"Cached images do not match"); } @end From 64974e28cc6ea6d63ec33c837536a37f9763eb34 Mon Sep 17 00:00:00 2001 From: frankenbot Date: Mon, 2 Nov 2015 22:53:41 -0800 Subject: [PATCH 28/40] Update redirects --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index d250fb8182..3bc814a2af 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ Choose AFNetworking for your next project, or migrate over your existing project ### Installation with CocoaPods -[CocoaPods](http://cocoapods.org) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like AFNetworking in your projects. See the ["Getting Started" guide for more information](https://github.com/AFNetworking/AFNetworking/wiki/Getting-Started-with-AFNetworking). +[CocoaPods](https://cocoapods.org/) is a dependency manager for Objective-C, which automates and simplifies the process of using 3rd-party libraries like AFNetworking in your projects. See the ["Getting Started" guide for more information](https://github.com/AFNetworking/AFNetworking/wiki/Getting-Started-with-AFNetworking). #### Podfile @@ -360,7 +360,7 @@ NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:@[...] ## Unit Tests -AFNetworking includes a suite of unit tests within the Tests subdirectory. In order to run the unit tests, you must install the testing dependencies via [CocoaPods](http://cocoapods.org/): +AFNetworking includes a suite of unit tests within the Tests subdirectory. In order to run the unit tests, you must install the testing dependencies via [CocoaPods](https://cocoapods.org//): $ cd Tests $ pod install @@ -369,7 +369,7 @@ Once testing dependencies are installed, you can execute the test suite via the ### Running Tests from the Command Line -Tests can also be run from the command line or within a continuous integration environment. The [`xcpretty`](https://github.com/mneorr/xcpretty) utility needs to be installed before running the tests from the command line: +Tests can also be run from the command line or within a continuous integration environment. The [`xcpretty`](https://github.com/supermarin/xcpretty) utility needs to be installed before running the tests from the command line: $ gem install xcpretty @@ -379,11 +379,11 @@ Once `xcpretty` is installed, you can execute the suite via `rake test`. AFNetworking is owned and maintained by the [Alamofire Software Foundation](http://alamofire.org). -AFNetworking was originally created by [Scott Raymond](https://github.com/sco/) and [Mattt Thompson](https://github.com/mattt/) in the development of [Gowalla for iPhone](http://en.wikipedia.org/wiki/Gowalla). +AFNetworking was originally created by [Scott Raymond](https://github.com/sco/) and [Mattt Thompson](https://github.com/mattt/) in the development of [Gowalla for iPhone](https://en.wikipedia.org/wiki/Gowalla). AFNetworking's logo was designed by [Alan Defibaugh](http://www.alandefibaugh.com/). -And most of all, thanks to AFNetworking's [growing list of contributors](https://github.com/AFNetworking/AFNetworking/contributors). +And most of all, thanks to AFNetworking's [growing list of contributors](https://github.com/AFNetworking/AFNetworking/graphs/contributors). ### Security Disclosure From 128954682b64131436dfd8415d05c5e4666b3d41 Mon Sep 17 00:00:00 2001 From: dkhamsing Date: Tue, 3 Nov 2015 09:04:03 -0800 Subject: [PATCH 29/40] Fix URL in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 3bc814a2af..87ec4b20a5 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,7 @@ NSArray *operations = [AFURLConnectionOperation batchOfRequestOperations:@[...] ## Unit Tests -AFNetworking includes a suite of unit tests within the Tests subdirectory. In order to run the unit tests, you must install the testing dependencies via [CocoaPods](https://cocoapods.org//): +AFNetworking includes a suite of unit tests within the Tests subdirectory. In order to run the unit tests, you must install the testing dependencies via [CocoaPods](https://cocoapods.org/): $ cd Tests $ pod install From 9f44d51da79c262e6587cc56427665db8c5b27de Mon Sep 17 00:00:00 2001 From: Michael Hackett Date: Wed, 4 Nov 2015 14:58:51 -0400 Subject: [PATCH 30/40] Make all reachability-status callbacks from the main GCD queue. Because the run-loop reachability callback executed its callback directly, whereas the initial check (fired off from `-[AFNetworkReachabilityManager startMonitoring]`) executed the callback from a GCD queue, it was possible for the callbacks to be executed out of order from when the status was obtained, leaving the listener in the incorrect state. By sending both routes through the same GCD-queuing function, both the callbacks and NSNotifications will be processed in the order in which they are sent. It also removes some repetition in the code. --- AFNetworking/AFNetworkReachabilityManager.m | 35 +++++++++++---------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/AFNetworking/AFNetworkReachabilityManager.m b/AFNetworking/AFNetworkReachabilityManager.m index 2e5e2edb15..7f9b8a3256 100644 --- a/AFNetworking/AFNetworkReachabilityManager.m +++ b/AFNetworking/AFNetworkReachabilityManager.m @@ -76,20 +76,28 @@ static AFNetworkReachabilityStatus AFNetworkReachabilityStatusForFlags(SCNetwork return status; } -static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) { +/** + * Queue a status change notification for the main thread. + * + * This is done to ensure that the notifications are received in the same order + * as they are sent. If notifications are sent directly, it is possible that + * a queued notification (for an earlier status condition) is processed after + * the later update, resulting in the listener being left in the wrong state. + */ +static void AFPostReachabilityStatusChange(SCNetworkReachabilityFlags flags, AFNetworkReachabilityStatusBlock block) { AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags); - AFNetworkReachabilityStatusBlock block = (__bridge AFNetworkReachabilityStatusBlock)info; - if (block) { - block(status); - } - - dispatch_async(dispatch_get_main_queue(), ^{ + if (block) { + block(status); + } NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; NSDictionary *userInfo = @{ AFNetworkingReachabilityNotificationStatusItem: @(status) }; [notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:userInfo]; }); +} +static void AFNetworkReachabilityCallback(SCNetworkReachabilityRef __unused target, SCNetworkReachabilityFlags flags, void *info) { + AFPostReachabilityStatusChange(flags, (__bridge AFNetworkReachabilityStatusBlock)info); } static const void * AFNetworkReachabilityRetainCallback(const void *info) { @@ -212,16 +220,9 @@ - (void)startMonitoring { default: { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{ SCNetworkReachabilityFlags flags; - SCNetworkReachabilityGetFlags((__bridge SCNetworkReachabilityRef)networkReachability, &flags); - AFNetworkReachabilityStatus status = AFNetworkReachabilityStatusForFlags(flags); - dispatch_async(dispatch_get_main_queue(), ^{ - callback(status); - - NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter]; - [notificationCenter postNotificationName:AFNetworkingReachabilityDidChangeNotification object:nil userInfo:@{ AFNetworkingReachabilityNotificationStatusItem: @(status) }]; - - - }); + if (SCNetworkReachabilityGetFlags((__bridge SCNetworkReachabilityRef)networkReachability, &flags)) { + AFPostReachabilityStatusChange(flags, callback); + } }); } break; From 07c18ad0ffa5b743f79885c7f6c8672c877737b0 Mon Sep 17 00:00:00 2001 From: Michael Hackett Date: Wed, 4 Nov 2015 14:59:58 -0400 Subject: [PATCH 31/40] Remove reachability-association type -- no longer need special case. It appears that a check was put in place to work around a race condition when reachability was associated with a domain name. However, the cause of the race condition is addressed in the previous commit, so the special-casing is no longer needed. --- AFNetworking/AFNetworkReachabilityManager.m | 28 ++++----------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/AFNetworking/AFNetworkReachabilityManager.m b/AFNetworking/AFNetworkReachabilityManager.m index 7f9b8a3256..543da2ff41 100644 --- a/AFNetworking/AFNetworkReachabilityManager.m +++ b/AFNetworking/AFNetworkReachabilityManager.m @@ -33,12 +33,6 @@ typedef void (^AFNetworkReachabilityStatusBlock)(AFNetworkReachabilityStatus status); -typedef NS_ENUM(NSUInteger, AFNetworkReachabilityAssociation) { - AFNetworkReachabilityForAddress = 1, - AFNetworkReachabilityForAddressPair = 2, - AFNetworkReachabilityForName = 3, -}; - NSString * AFStringFromNetworkReachabilityStatus(AFNetworkReachabilityStatus status) { switch (status) { case AFNetworkReachabilityStatusNotReachable: @@ -112,7 +106,6 @@ static void AFNetworkReachabilityReleaseCallback(const void *info) { @interface AFNetworkReachabilityManager () @property (readwrite, nonatomic, strong) id networkReachability; -@property (readwrite, nonatomic, assign) AFNetworkReachabilityAssociation networkReachabilityAssociation; @property (readwrite, nonatomic, assign) AFNetworkReachabilityStatus networkReachabilityStatus; @property (readwrite, nonatomic, copy) AFNetworkReachabilityStatusBlock networkReachabilityStatusBlock; @end @@ -138,7 +131,6 @@ + (instancetype)managerForDomain:(NSString *)domain { SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [domain UTF8String]); AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability]; - manager.networkReachabilityAssociation = AFNetworkReachabilityForName; return manager; } @@ -147,7 +139,6 @@ + (instancetype)managerForAddress:(const void *)address { SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address); AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability]; - manager.networkReachabilityAssociation = AFNetworkReachabilityForAddress; return manager; } @@ -212,21 +203,12 @@ - (void)startMonitoring { SCNetworkReachabilitySetCallback((__bridge SCNetworkReachabilityRef)networkReachability, AFNetworkReachabilityCallback, &context); SCNetworkReachabilityScheduleWithRunLoop((__bridge SCNetworkReachabilityRef)networkReachability, CFRunLoopGetMain(), kCFRunLoopCommonModes); - switch (self.networkReachabilityAssociation) { - case AFNetworkReachabilityForName: - break; - case AFNetworkReachabilityForAddress: - case AFNetworkReachabilityForAddressPair: - default: { - dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{ - SCNetworkReachabilityFlags flags; - if (SCNetworkReachabilityGetFlags((__bridge SCNetworkReachabilityRef)networkReachability, &flags)) { - AFPostReachabilityStatusChange(flags, callback); - } - }); + dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0),^{ + SCNetworkReachabilityFlags flags; + if (SCNetworkReachabilityGetFlags((__bridge SCNetworkReachabilityRef)networkReachability, &flags)) { + AFPostReachabilityStatusChange(flags, callback); } - break; - } + }); } - (void)stopMonitoring { From aa81eb47d45c9a98789eb28df20ba75138c865a3 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Fri, 6 Nov 2015 08:37:11 -0600 Subject: [PATCH 32/40] Fixed swift interop issue with throws and Request/Response serialization Fix for #2810 --- AFNetworking/AFURLRequestSerialization.h | 2 +- AFNetworking/AFURLResponseSerialization.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/AFNetworking/AFURLRequestSerialization.h b/AFNetworking/AFURLRequestSerialization.h index ef4d3661bd..d602094516 100644 --- a/AFNetworking/AFURLRequestSerialization.h +++ b/AFNetworking/AFURLRequestSerialization.h @@ -46,7 +46,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request withParameters:(nullable id)parameters - error:(NSError * __nullable __autoreleasing *)error; + error:(NSError * __nullable __autoreleasing *)error NS_SWIFT_NOTHROW; @end diff --git a/AFNetworking/AFURLResponseSerialization.h b/AFNetworking/AFURLResponseSerialization.h index 1396cfbd11..2aa620d2b6 100644 --- a/AFNetworking/AFURLResponseSerialization.h +++ b/AFNetworking/AFURLResponseSerialization.h @@ -42,7 +42,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable id)responseObjectForResponse:(nullable NSURLResponse *)response data:(nullable NSData *)data - error:(NSError * __nullable __autoreleasing *)error; + error:(NSError * __nullable __autoreleasing *)error NS_SWIFT_NOTHROW; @end From 8acca137a443bc123df0a23034a006f6348d6a36 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Fri, 6 Nov 2015 09:03:06 -0600 Subject: [PATCH 33/40] Suppressed false positive memory leak warning in Reachability Manager Fix for #3110 --- AFNetworking/AFNetworkReachabilityManager.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFNetworkReachabilityManager.m b/AFNetworking/AFNetworkReachabilityManager.m index 2e5e2edb15..b8c8bc3403 100644 --- a/AFNetworking/AFNetworkReachabilityManager.m +++ b/AFNetworking/AFNetworkReachabilityManager.m @@ -127,21 +127,24 @@ + (instancetype)sharedManager { } + (instancetype)managerForDomain:(NSString *)domain { +#ifndef __clang_analyzer__ SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [domain UTF8String]); AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability]; manager.networkReachabilityAssociation = AFNetworkReachabilityForName; return manager; +#endif } + (instancetype)managerForAddress:(const void *)address { +#ifndef __clang_analyzer__ SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address); - AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability]; manager.networkReachabilityAssociation = AFNetworkReachabilityForAddress; return manager; +#endif } - (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability { From d6929054c7e618da234a062d430a3ec61221d386 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Fri, 6 Nov 2015 09:16:47 -0600 Subject: [PATCH 34/40] Updated travis to run on 7.1 --- .travis.yml | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index c531ee656f..9b56c0055c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,16 +1,17 @@ language: objective-c -osx_image: xcode7 +osx_image: xcode7.1 sudo: false env: global: - LC_CTYPE=en_US.UTF-8 - LANG=en_US.UTF-8 matrix: - - DESTINATION="OS=9.0,name=iPhone 6 Plus" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO" - - DESTINATION="OS=8.1,name=iPhone 4S" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="YES" - - DESTINATION="OS=8.2,name=iPhone 5" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - DESTINATION="OS=8.3,name=iPhone 5S" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" - - DESTINATION="OS=8.4,name=iPhone 6" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.0 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" + - DESTINATION="OS=9.1,name=iPhone 6s" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.1 RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO" + - DESTINATION="OS=9.0,name=iPhone 6 Plus" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.1 RUN_TESTS="YES" BUILD_EXAMPLE="YES" POD_LINT="NO" + - DESTINATION="OS=8.4,name=iPhone 6" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.1 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" + - DESTINATION="OS=8.3,name=iPhone 5S" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.1 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" + - DESTINATION="OS=8.2,name=iPhone 5" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.1 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="NO" + - DESTINATION="OS=8.1,name=iPhone 4S" TEST_SCHEME="iOS Tests" EXAMPLE_SCHEME="AFNetworking iOS Example" SDK=iphonesimulator9.1 RUN_TESTS="YES" BUILD_EXAMPLE="NO" POD_LINT="YES" # TESTS ARE CURRENTLY DISABLED FOR MAC OS X DUE TO THIS ISSUE: https://github.com/travis-ci/travis-ci/issues/4904 - DESTINATION="arch=x86_64" TEST_SCHEME="OS X Tests" SDK=macosx10.11 EXAMPLE_SCHEME="AFNetworking Example" RUN_TESTS="NO" BUILD_EXAMPLE="YES" POD_LINT="NO" before_install: From 105fc642f9566eec3ffc8b70f2319ef03f3464b6 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Fri, 6 Nov 2015 09:24:31 -0600 Subject: [PATCH 35/40] Fixed swift interop issue that prevented returning a nil NSURL for a download task Fix for #3104 and #3043 --- AFNetworking/AFURLSessionManager.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AFNetworking/AFURLSessionManager.h b/AFNetworking/AFURLSessionManager.h index f251b832b5..cbbf3773f1 100644 --- a/AFNetworking/AFURLSessionManager.h +++ b/AFNetworking/AFURLSessionManager.h @@ -428,7 +428,7 @@ NS_ASSUME_NONNULL_BEGIN @param block A block object to be executed when a download task has completed. The block returns the URL the download should be moved to, and takes three arguments: the session, the download task, and the temporary location of the downloaded file. If the file manager encounters an error while attempting to move the temporary file to the destination, an `AFURLSessionDownloadTaskDidFailToMoveFileNotification` will be posted, with the download task as its object, and the user info of the error. */ -- (void)setDownloadTaskDidFinishDownloadingBlock:(nullable NSURL * (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block; +- (void)setDownloadTaskDidFinishDownloadingBlock:(nullable NSURL * _Nullable (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block; /** Sets a block to be executed periodically to track download progress, as handled by the `NSURLSessionDownloadDelegate` method `URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesWritten:totalBytesExpectedToWrite:`. From 928858869dfb09714f3828413a0366d6374e08a0 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Fri, 6 Nov 2015 13:53:20 -0600 Subject: [PATCH 36/40] Prepping for the 2.6.2 release --- AFNetworking.podspec | 2 +- CHANGELOG.md | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index 363a815be0..009af9e0d0 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'AFNetworking' - s.version = '2.6.1' + s.version = '2.6.2' s.license = 'MIT' s.summary = 'A delightful iOS and OS X networking framework.' s.homepage = 'https://github.com/AFNetworking/AFNetworking' diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d095a7fbd..a21fe21910 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,43 @@ All notable changes to this project will be documented in this file. `AFNetworking` adheres to [Semantic Versioning](http://semver.org/). ---- +--- + +##[2.6.2](https://github.com/AFNetworking/AFNetworking/releases/tag/2.6.2) (11/06/2015) +Released on Friday, November 06, 2015. All issues associated with this milestone can be found using this [filter](https://github.com/AFNetworking/AFNetworking/issues?q=milestone%3A2.6.2+is%3Aclosed). + +#### Added +* `AFHTTPSessionManager` now copies its `securityPolicy` + * Fixed by [mohamede1945](https://github.com/mohamede1945) in [#2887](https://github.com/AFNetworking/AFNetworking/pull/2887). + +#### Updated +* Updated travis to run on 7.1 + * Fixed by [kcharwood](https://github.com/kcharwood) in [#3132](https://github.com/AFNetworking/AFNetworking/pull/3132). +* Simplifications of if and return statements in `AFSecurityPolicy` + * Fixed by [TorreyBetts](https://github.com/TorreyBetts) in [#3063](https://github.com/AFNetworking/AFNetworking/pull/3063). + +#### Fixed +* Fixed swift interop issue that prevented returning a nil NSURL for a download task + * Fixed by [kcharwood](https://github.com/kcharwood) in [#3133](https://github.com/AFNetworking/AFNetworking/pull/3133). +* Suppressed false positive memory leak warning in Reachability Manager + * Fixed by [kcharwood](https://github.com/kcharwood) in [#3131](https://github.com/AFNetworking/AFNetworking/pull/3131). +* Fixed swift interop issue with throws and Request/Response serialization + * Fixed by [kcharwood](https://github.com/kcharwood) in [#3130](https://github.com/AFNetworking/AFNetworking/pull/3130). +* Fixed race condition in reachability callback delivery + * Fixed by [MichaelHackett](https://github.com/MichaelHackett) in [#3117](https://github.com/AFNetworking/AFNetworking/pull/3117). +* Fixed URLs that were redirecting in the README + * Fixed by [frankenbot](https://github.com/frankenbot) in [#3109](https://github.com/AFNetworking/AFNetworking/pull/3109). +* Fixed Project Warnings + * Fixed by [kcharwood](https://github.com/kcharwood) in [#3102](https://github.com/AFNetworking/AFNetworking/pull/3102). +* Fixed README link to WWDC session + * Fixed by [wrtsprt](https://github.com/wrtsprt) in [#3099](https://github.com/AFNetworking/AFNetworking/pull/3099). +* Switched from `OS_OBJECT_HAVE_OBJC_SUPPORT` to `OS_OBJECT_USE_OBJC` for watchOS 2 support. + * Fixed by [kylef](https://github.com/kylef) in [#3065](https://github.com/AFNetworking/AFNetworking/pull/3065). +* Added missing __nullable attributes to failure blocks in `AFHTTPRequestOperationManager` and `AFHTTPSessionManager` + * Fixed by [hoppenichu](https://github.com/hoppenichu) in [#3057](https://github.com/AFNetworking/AFNetworking/pull/3057). +* Fixed memory leak in NSURLSession handling + * Fixed by [olegnaumenko](https://github.com/olegnaumenko) in [#2794](https://github.com/AFNetworking/AFNetworking/pull/2794). + ## [2.6.1](https://github.com/AFNetworking/AFNetworking/releases/tag/2.6.1) (10-13-2015) Released on Tuesday, October 13th, 2015. All issues associated with this milestone can be found using this [filter](https://github.com/AFNetworking/AFNetworking/issues?q=milestone%3A2.6.1+is%3Aclosed). From 51e86a901c81eebbaefe0cfab19f3c41ce06a544 Mon Sep 17 00:00:00 2001 From: Julien Cayzac Date: Mon, 9 Nov 2015 12:36:51 +0900 Subject: [PATCH 37/40] Xcode 6 compatibility (#3137) --- AFNetworking/AFURLRequestSerialization.h | 7 +++++-- AFNetworking/AFURLResponseSerialization.h | 6 +++++- AFNetworking/AFURLSessionManager.h | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFURLRequestSerialization.h b/AFNetworking/AFURLRequestSerialization.h index d602094516..15ced1dd0c 100644 --- a/AFNetworking/AFURLRequestSerialization.h +++ b/AFNetworking/AFURLRequestSerialization.h @@ -46,8 +46,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLRequest *)requestBySerializingRequest:(NSURLRequest *)request withParameters:(nullable id)parameters - error:(NSError * __nullable __autoreleasing *)error NS_SWIFT_NOTHROW; - + error:(NSError * __nullable __autoreleasing *)error +#ifdef NS_SWIFT_NOTHROW +NS_SWIFT_NOTHROW +#endif +; @end #pragma mark - diff --git a/AFNetworking/AFURLResponseSerialization.h b/AFNetworking/AFURLResponseSerialization.h index 2aa620d2b6..1578b78171 100644 --- a/AFNetworking/AFURLResponseSerialization.h +++ b/AFNetworking/AFURLResponseSerialization.h @@ -42,7 +42,11 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable id)responseObjectForResponse:(nullable NSURLResponse *)response data:(nullable NSData *)data - error:(NSError * __nullable __autoreleasing *)error NS_SWIFT_NOTHROW; + error:(NSError * __nullable __autoreleasing *)error +#ifdef NS_SWIFT_NOTHROW +NS_SWIFT_NOTHROW +#endif +; @end diff --git a/AFNetworking/AFURLSessionManager.h b/AFNetworking/AFURLSessionManager.h index cbbf3773f1..4498c89294 100644 --- a/AFNetworking/AFURLSessionManager.h +++ b/AFNetworking/AFURLSessionManager.h @@ -428,7 +428,7 @@ NS_ASSUME_NONNULL_BEGIN @param block A block object to be executed when a download task has completed. The block returns the URL the download should be moved to, and takes three arguments: the session, the download task, and the temporary location of the downloaded file. If the file manager encounters an error while attempting to move the temporary file to the destination, an `AFURLSessionDownloadTaskDidFailToMoveFileNotification` will be posted, with the download task as its object, and the user info of the error. */ -- (void)setDownloadTaskDidFinishDownloadingBlock:(nullable NSURL * _Nullable (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block; +- (void)setDownloadTaskDidFinishDownloadingBlock:(nullable NSURL * __nullable (^)(NSURLSession *session, NSURLSessionDownloadTask *downloadTask, NSURL *location))block; /** Sets a block to be executed periodically to track download progress, as handled by the `NSURLSessionDownloadDelegate` method `URLSession:downloadTask:didWriteData:totalBytesWritten:totalBytesWritten:totalBytesExpectedToWrite:`. From a55cfc098201ccafa81a06bab07119c4158d425c Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Mon, 9 Nov 2015 09:00:12 -0600 Subject: [PATCH 38/40] Updated changelog for #31377 --- CHANGELOG.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a21fe21910..4217ea49f4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ All notable changes to this project will be documented in this file. ##[2.6.2](https://github.com/AFNetworking/AFNetworking/releases/tag/2.6.2) (11/06/2015) Released on Friday, November 06, 2015. All issues associated with this milestone can be found using this [filter](https://github.com/AFNetworking/AFNetworking/issues?q=milestone%3A2.6.2+is%3Aclosed). +### Important Upgrade Note for Swift +* [#3130](https://github.com/AFNetworking/AFNetworking/pull/3130) fixes a swift interop error that does have a breaking API change if you are using Swift. This was [identified](https://github.com/AFNetworking/AFNetworking/issues/3137) after 2.6.2 was released. It changes the method from `throws` to an error pointer, since that method does return an object and also handles an error pointer, which does not play nicely with the Swift/Objective-C error conversion. See [#2810](https://github.com/AFNetworking/AFNetworking/issues/2810) for additional notes. This affects `AFURLRequestionSerializer` and `AFURLResponseSerializer`. + #### Added * `AFHTTPSessionManager` now copies its `securityPolicy` * Fixed by [mohamede1945](https://github.com/mohamede1945) in [#2887](https://github.com/AFNetworking/AFNetworking/pull/2887). @@ -22,7 +25,7 @@ Released on Friday, November 06, 2015. All issues associated with this milestone * Fixed by [kcharwood](https://github.com/kcharwood) in [#3133](https://github.com/AFNetworking/AFNetworking/pull/3133). * Suppressed false positive memory leak warning in Reachability Manager * Fixed by [kcharwood](https://github.com/kcharwood) in [#3131](https://github.com/AFNetworking/AFNetworking/pull/3131). -* Fixed swift interop issue with throws and Request/Response serialization +* Fixed swift interop issue with throws and Request/Response serialization. * Fixed by [kcharwood](https://github.com/kcharwood) in [#3130](https://github.com/AFNetworking/AFNetworking/pull/3130). * Fixed race condition in reachability callback delivery * Fixed by [MichaelHackett](https://github.com/MichaelHackett) in [#3117](https://github.com/AFNetworking/AFNetworking/pull/3117). From 085a4dcfa43082f71ba279a8aa711867dc86e115 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Mon, 9 Nov 2015 10:26:28 -0600 Subject: [PATCH 39/40] Fixed issue clang analyzer warning suppression that preventing building under some project configurations Fix for #3138 --- AFNetworking/AFNetworkReachabilityManager.m | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/AFNetworking/AFNetworkReachabilityManager.m b/AFNetworking/AFNetworkReachabilityManager.m index 48e7ecbd36..fe67781e3c 100644 --- a/AFNetworking/AFNetworkReachabilityManager.m +++ b/AFNetworking/AFNetworkReachabilityManager.m @@ -127,24 +127,24 @@ + (instancetype)sharedManager { return _sharedManager; } -+ (instancetype)managerForDomain:(NSString *)domain { #ifndef __clang_analyzer__ ++ (instancetype)managerForDomain:(NSString *)domain { SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithName(kCFAllocatorDefault, [domain UTF8String]); AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability]; return manager; -#endif } +#endif -+ (instancetype)managerForAddress:(const void *)address { #ifndef __clang_analyzer__ ++ (instancetype)managerForAddress:(const void *)address { SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address); AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability]; return manager; -#endif } +#endif - (instancetype)initWithReachability:(SCNetworkReachabilityRef)reachability { self = [super init]; From ee89cc988e2709a025908ef952a7377ce7ba83b8 Mon Sep 17 00:00:00 2001 From: Kevin Harwood Date: Wed, 11 Nov 2015 08:37:27 -0600 Subject: [PATCH 40/40] Preparing for the 2.6.3 release --- AFNetworking.podspec | 2 +- CHANGELOG.md | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/AFNetworking.podspec b/AFNetworking.podspec index 009af9e0d0..eae9331dc3 100644 --- a/AFNetworking.podspec +++ b/AFNetworking.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'AFNetworking' - s.version = '2.6.2' + s.version = '2.6.3' s.license = 'MIT' s.summary = 'A delightful iOS and OS X networking framework.' s.homepage = 'https://github.com/AFNetworking/AFNetworking' diff --git a/CHANGELOG.md b/CHANGELOG.md index 4217ea49f4..b7dc7354b6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,16 @@ All notable changes to this project will be documented in this file. --- +##[2.6.3](https://github.com/AFNetworking/AFNetworking/releases/tag/2.6.3) (11/11/2015) +Released on Wednesday, November 11, 2015. All issues associated with this milestone can be found using this [filter](https://github.com/AFNetworking/AFNetworking/issues?q=milestone%3A2.6.3+is%3Aclosed). + +#### Fixed +* Fixed clang analyzer warning suppression that prevented building under some project configurations + * Fixed by [kcharwood](https://github.com/kcharwood) in [#3142](https://github.com/AFNetworking/AFNetworking/pull/3142). +* Restored Xcode 6 compatibility + * Fixed by [jcayzac](https://github.com/jcayzac) in [#3139](https://github.com/AFNetworking/AFNetworking/pull/3139). + + ##[2.6.2](https://github.com/AFNetworking/AFNetworking/releases/tag/2.6.2) (11/06/2015) Released on Friday, November 06, 2015. All issues associated with this milestone can be found using this [filter](https://github.com/AFNetworking/AFNetworking/issues?q=milestone%3A2.6.2+is%3Aclosed).