diff --git a/src/ios/AFNetworking/AFHTTPSessionManager.h b/src/ios/AFNetworking/AFHTTPSessionManager.h index 61e1042..5ce279a 100644 --- a/src/ios/AFNetworking/AFHTTPSessionManager.h +++ b/src/ios/AFNetworking/AFHTTPSessionManager.h @@ -1,5 +1,5 @@ // AFHTTPSessionManager.h -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -150,7 +150,7 @@ NS_ASSUME_NONNULL_BEGIN @param URLString The URL string used to create the request URL. @param parameters The parameters to be encoded according to the client request serializer. - @param progress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. + @param downloadProgress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer. @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred. @@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLSessionDataTask *)GET:(NSString *)URLString parameters:(nullable id)parameters - progress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgress + progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgress success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure; @@ -197,7 +197,7 @@ NS_ASSUME_NONNULL_BEGIN @param URLString The URL string used to create the request URL. @param parameters The parameters to be encoded according to the client request serializer. - @param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. + @param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer. @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred. @@ -205,7 +205,7 @@ NS_ASSUME_NONNULL_BEGIN */ - (nullable NSURLSessionDataTask *)POST:(NSString *)URLString parameters:(nullable id)parameters - progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgress + progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure; @@ -232,7 +232,7 @@ NS_ASSUME_NONNULL_BEGIN @param URLString The URL string used to create the request URL. @param parameters The parameters to be encoded according to the client request serializer. @param block A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the `AFMultipartFormData` protocol. - @param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. + @param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer. @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred. @@ -241,7 +241,7 @@ NS_ASSUME_NONNULL_BEGIN - (nullable NSURLSessionDataTask *)POST:(NSString *)URLString parameters:(nullable id)parameters constructingBodyWithBlock:(nullable void (^)(id formData))block - progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgress + progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure; diff --git a/src/ios/AFNetworking/AFHTTPSessionManager.m b/src/ios/AFNetworking/AFHTTPSessionManager.m index 249631b..2b0c1d0 100644 --- a/src/ios/AFNetworking/AFHTTPSessionManager.m +++ b/src/ios/AFNetworking/AFHTTPSessionManager.m @@ -1,5 +1,5 @@ // AFHTTPSessionManager.m -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -186,12 +186,9 @@ NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError]; if (serializationError) { if (failure) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu" dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{ failure(nil, serializationError); }); -#pragma clang diagnostic pop } return nil; @@ -262,12 +259,9 @@ NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError]; if (serializationError) { if (failure) { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu" dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{ failure(nil, serializationError); }); -#pragma clang diagnostic pop } return nil; diff --git a/src/ios/AFNetworking/AFNetworkReachabilityManager.h b/src/ios/AFNetworking/AFNetworkReachabilityManager.h index 88d9181..0feb18d 100644 --- a/src/ios/AFNetworking/AFNetworkReachabilityManager.h +++ b/src/ios/AFNetworking/AFNetworkReachabilityManager.h @@ -1,5 +1,5 @@ // AFNetworkReachabilityManager.h -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -38,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability. - See Apple's Reachability Sample Code (https://developer.apple.com/library/ios/samplecode/reachability/) + See Apple's Reachability Sample Code ( https://developer.apple.com/library/ios/samplecode/reachability/ ) @warning Instances of `AFNetworkReachabilityManager` must be started with `-startMonitoring` before reachability status can be determined. */ diff --git a/src/ios/AFNetworking/AFNetworkReachabilityManager.m b/src/ios/AFNetworking/AFNetworkReachabilityManager.m index d39b81b..d458364 100644 --- a/src/ios/AFNetworking/AFNetworkReachabilityManager.m +++ b/src/ios/AFNetworking/AFNetworkReachabilityManager.m @@ -1,5 +1,5 @@ // AFNetworkReachabilityManager.m -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/src/ios/AFNetworking/AFSecurityPolicy.h b/src/ios/AFNetworking/AFSecurityPolicy.h index de3ce92..c005efa 100644 --- a/src/ios/AFNetworking/AFSecurityPolicy.h +++ b/src/ios/AFNetworking/AFSecurityPolicy.h @@ -1,5 +1,5 @@ // AFSecurityPolicy.h -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/src/ios/AFNetworking/AFSecurityPolicy.m b/src/ios/AFNetworking/AFSecurityPolicy.m index 34a10d7..70418cb 100644 --- a/src/ios/AFNetworking/AFSecurityPolicy.m +++ b/src/ios/AFNetworking/AFSecurityPolicy.m @@ -1,5 +1,5 @@ // AFSecurityPolicy.m -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/src/ios/AFNetworking/AFURLRequestSerialization.h b/src/ios/AFNetworking/AFURLRequestSerialization.h index a6f179b..694696b 100644 --- a/src/ios/AFNetworking/AFURLRequestSerialization.h +++ b/src/ios/AFNetworking/AFURLRequestSerialization.h @@ -1,5 +1,5 @@ // AFURLRequestSerialization.h -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/src/ios/AFNetworking/AFURLRequestSerialization.m b/src/ios/AFNetworking/AFURLRequestSerialization.m index 086e674..a47e2e6 100644 --- a/src/ios/AFNetworking/AFURLRequestSerialization.m +++ b/src/ios/AFNetworking/AFURLRequestSerialization.m @@ -1,5 +1,5 @@ // AFURLRequestSerialization.m -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -60,10 +60,7 @@ NSString * AFPercentEscapedStringFromString(NSString *string) { 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 👴🏻👮🏽 @@ -219,8 +216,6 @@ static void *AFHTTPRequestSerializerObserverContext = &AFHTTPRequestSerializerOb [self setValue:[acceptLanguagesComponents componentsJoinedByString:@", "] forHTTPHeaderField:@"Accept-Language"]; NSString *userAgent = nil; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu" #if TARGET_OS_IOS // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]]; @@ -230,7 +225,6 @@ static void *AFHTTPRequestSerializerObserverContext = &AFHTTPRequestSerializerOb #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]; #endif -#pragma clang diagnostic pop if (userAgent) { if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) { NSMutableString *mutableUserAgent = [userAgent mutableCopy]; @@ -500,7 +494,7 @@ forHTTPHeaderField:(NSString *)field } if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) { - if (query) { + if (query && query.length > 0) { mutableRequest.URL = [NSURL URLWithString:[[mutableRequest.URL absoluteString] stringByAppendingFormat:mutableRequest.URL.query ? @"&%@" : @"?%@", query]]; } } else { @@ -835,14 +829,11 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; @end @implementation AFMultipartBodyStream -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wimplicit-atomic-properties" #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1100) @synthesize delegate; #endif @synthesize streamStatus; @synthesize streamError; -#pragma clang diagnostic pop - (instancetype)initWithStringEncoding:(NSStringEncoding)encoding { self = [super init]; @@ -888,8 +879,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; NSInteger totalNumberOfBytesRead = 0; -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu" while ((NSUInteger)totalNumberOfBytesRead < MIN(length, self.numberOfBytesInPacket)) { if (!self.currentHTTPBodyPart || ![self.currentHTTPBodyPart hasBytesAvailable]) { if (!(self.currentHTTPBodyPart = [self.HTTPBodyPartEnumerator nextObject])) { @@ -910,7 +899,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2; } } } -#pragma clang diagnostic pop return totalNumberOfBytesRead; } @@ -1091,8 +1079,6 @@ typedef enum { return YES; } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wcovered-switch-default" switch (self.inputStream.streamStatus) { case NSStreamStatusNotOpen: case NSStreamStatusOpening: @@ -1106,7 +1092,6 @@ typedef enum { default: return NO; } -#pragma clang diagnostic pop } - (NSInteger)read:(uint8_t *)buffer @@ -1151,11 +1136,8 @@ typedef enum { intoBuffer:(uint8_t *)buffer maxLength:(NSUInteger)length { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu" NSRange range = NSMakeRange((NSUInteger)_phaseReadOffset, MIN([data length] - ((NSUInteger)_phaseReadOffset), length)); [data getBytes:buffer range:range]; -#pragma clang diagnostic pop _phaseReadOffset += range.length; @@ -1174,8 +1156,6 @@ typedef enum { return YES; } -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wcovered-switch-default" switch (_phase) { case AFEncapsulationBoundaryPhase: _phase = AFHeaderPhase; @@ -1195,7 +1175,6 @@ typedef enum { break; } _phaseReadOffset = 0; -#pragma clang diagnostic pop return YES; } diff --git a/src/ios/AFNetworking/AFURLResponseSerialization.h b/src/ios/AFNetworking/AFURLResponseSerialization.h index c1357ae..a9430ad 100644 --- a/src/ios/AFNetworking/AFURLResponseSerialization.h +++ b/src/ios/AFNetworking/AFURLResponseSerialization.h @@ -1,5 +1,5 @@ // AFURLResponseSerialization.h -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal diff --git a/src/ios/AFNetworking/AFURLResponseSerialization.m b/src/ios/AFNetworking/AFURLResponseSerialization.m index 1402e8d..5e46799 100755 --- a/src/ios/AFNetworking/AFURLResponseSerialization.m +++ b/src/ios/AFNetworking/AFURLResponseSerialization.m @@ -1,5 +1,5 @@ // AFURLResponseSerialization.m -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -115,7 +115,9 @@ static id AFJSONObjectByRemovingKeysWithNullValues(id JSONObject, NSJSONReadingO NSError *validationError = nil; if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) { - if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]]) { + if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]] && + !([response MIMEType] == nil && [data length] == 0)) { + if ([data length] > 0 && [response URL]) { NSMutableDictionary *mutableUserInfo = [@{ NSLocalizedDescriptionKey: [NSString stringWithFormat:NSLocalizedStringFromTable(@"Request failed: unacceptable content-type: %@", @"AFNetworking", nil), [response MIMEType]], diff --git a/src/ios/AFNetworking/AFURLSessionManager.h b/src/ios/AFNetworking/AFURLSessionManager.h index 691e80c..89909fe 100644 --- a/src/ios/AFNetworking/AFURLSessionManager.h +++ b/src/ios/AFNetworking/AFURLSessionManager.h @@ -1,5 +1,5 @@ // AFURLSessionManager.h -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -51,6 +51,7 @@ - `URLSession:willPerformHTTPRedirection:newRequest:completionHandler:` - `URLSession:task:didReceiveChallenge:completionHandler:` - `URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:` + - `URLSession:task:needNewBodyStream:` - `URLSession:task:didCompleteWithError:` ### `NSURLSessionDataDelegate` @@ -213,13 +214,13 @@ NS_ASSUME_NONNULL_BEGIN Creates an `NSURLSessionDataTask` with the specified request. @param request The HTTP request for the request. - @param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. - @param downloadProgress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. + @param uploadProgressBlock A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. + @param downloadProgressBlock A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. @param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any. */ - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request - uploadProgress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock - downloadProgress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock + uploadProgress:(nullable void (^)(NSProgress *uploadProgress))uploadProgressBlock + downloadProgress:(nullable void (^)(NSProgress *downloadProgress))downloadProgressBlock completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler; ///--------------------------- @@ -231,14 +232,14 @@ NS_ASSUME_NONNULL_BEGIN @param request The HTTP request for the request. @param fileURL A URL to the local file to be uploaded. - @param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. + @param uploadProgressBlock A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any. @see `attemptsToRecreateUploadTasksForBackgroundSessions` */ - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromFile:(NSURL *)fileURL - progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock + progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgressBlock completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler; /** @@ -246,23 +247,23 @@ NS_ASSUME_NONNULL_BEGIN @param request The HTTP request for the request. @param bodyData A data object containing the HTTP body to be uploaded. - @param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. + @param uploadProgressBlock A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any. */ - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request fromData:(nullable NSData *)bodyData - progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock + progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgressBlock completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler; /** Creates an `NSURLSessionUploadTask` with the specified streaming request. @param request The HTTP request for the request. - @param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. + @param uploadProgressBlock A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any. */ - (NSURLSessionUploadTask *)uploadTaskWithStreamedRequest:(NSURLRequest *)request - progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock + progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgressBlock completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler; ///----------------------------- @@ -273,14 +274,14 @@ NS_ASSUME_NONNULL_BEGIN Creates an `NSURLSessionDownloadTask` with the specified request. @param request The HTTP request for the request. - @param progress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. + @param downloadProgressBlock A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. @param destination A block object to be executed in order to determine the destination of the downloaded file. This block takes two arguments, the target path & the server response, and returns the desired file URL of the resulting download. The temporary file used during the download will be automatically deleted after being moved to the returned URL. @param completionHandler A block to be executed when a task finishes. This block has no return value and takes three arguments: the server response, the path of the downloaded file, and the error describing the network or parsing error that occurred, if any. @warning If using a background `NSURLSessionConfiguration` on iOS, these blocks will be lost when the app is terminated. Background sessions may prefer to use `-setDownloadTaskDidFinishDownloadingBlock:` to specify the URL for saving the downloaded file, rather than the destination block of this method. */ - (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request - progress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock + progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgressBlock destination:(nullable NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination completionHandler:(nullable void (^)(NSURLResponse *response, NSURL * _Nullable filePath, NSError * _Nullable error))completionHandler; @@ -288,12 +289,12 @@ NS_ASSUME_NONNULL_BEGIN Creates an `NSURLSessionDownloadTask` with the specified resume data. @param resumeData The data used to resume downloading. - @param progress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. + @param downloadProgressBlock A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. @param destination A block object to be executed in order to determine the destination of the downloaded file. This block takes two arguments, the target path & the server response, and returns the desired file URL of the resulting download. The temporary file used during the download will be automatically deleted after being moved to the returned URL. @param completionHandler A block to be executed when a task finishes. This block has no return value and takes three arguments: the server response, the path of the downloaded file, and the error describing the network or parsing error that occurred, if any. */ - (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData - progress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock + progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgressBlock destination:(nullable NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination completionHandler:(nullable void (^)(NSURLResponse *response, NSURL * _Nullable filePath, NSError * _Nullable error))completionHandler; diff --git a/src/ios/AFNetworking/AFURLSessionManager.m b/src/ios/AFNetworking/AFURLSessionManager.m index 170581a..ef52968 100644 --- a/src/ios/AFNetworking/AFURLSessionManager.m +++ b/src/ios/AFNetworking/AFURLSessionManager.m @@ -1,5 +1,5 @@ // AFURLSessionManager.m -// Copyright (c) 2011–2016 Alamofire Software Foundation (http://alamofire.org/) +// Copyright (c) 2011–2016 Alamofire Software Foundation ( http://alamofire.org/ ) // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal @@ -85,8 +85,6 @@ static NSString * const AFURLSessionManagerLockName = @"com.alamofire.networking static NSUInteger const AFMaximumNumberOfAttemptsToRecreateBackgroundSessionUploadTask = 3; -static void * AFTaskStateChangedContext = &AFTaskStateChangedContext; - typedef void (^AFURLSessionDidBecomeInvalidBlock)(NSURLSession *session, NSError *error); typedef NSURLSessionAuthChallengeDisposition (^AFURLSessionDidReceiveAuthenticationChallengeBlock)(NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential); @@ -224,13 +222,13 @@ typedef void (^AFURLSessionTaskCompletionHandler)(NSURLResponse *response, id re - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { if ([object isKindOfClass:[NSURLSessionTask class]] || [object isKindOfClass:[NSURLSessionDownloadTask class]]) { if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesReceived))]) { - self.downloadProgress.completedUnitCount = [change[@"new"] longLongValue]; + self.downloadProgress.completedUnitCount = [change[NSKeyValueChangeNewKey] longLongValue]; } else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesExpectedToReceive))]) { - self.downloadProgress.totalUnitCount = [change[@"new"] longLongValue]; + self.downloadProgress.totalUnitCount = [change[NSKeyValueChangeNewKey] longLongValue]; } else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesSent))]) { - self.uploadProgress.completedUnitCount = [change[@"new"] longLongValue]; + self.uploadProgress.completedUnitCount = [change[NSKeyValueChangeNewKey] longLongValue]; } else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesExpectedToSend))]) { - self.uploadProgress.totalUnitCount = [change[@"new"] longLongValue]; + self.uploadProgress.totalUnitCount = [change[NSKeyValueChangeNewKey] longLongValue]; } } else if ([object isEqual:self.downloadProgress]) { @@ -251,8 +249,6 @@ typedef void (^AFURLSessionTaskCompletionHandler)(NSURLResponse *response, id re task:(NSURLSessionTask *)task didCompleteWithError:(NSError *)error { -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wgnu" __strong AFURLSessionManager *manager = self.manager; __block id responseObject = nil; @@ -314,7 +310,6 @@ didCompleteWithError:(NSError *)error }); }); } -#pragma clang diagnostic pop } #pragma mark - NSURLSessionDataTaskDelegate @@ -983,7 +978,7 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge disposition = NSURLSessionAuthChallengePerformDefaultHandling; } } else { - disposition = NSURLSessionAuthChallengeRejectProtectionSpace; + disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge; } } else { disposition = NSURLSessionAuthChallengePerformDefaultHandling; @@ -1030,7 +1025,7 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge disposition = NSURLSessionAuthChallengeUseCredential; credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; } else { - disposition = NSURLSessionAuthChallengeRejectProtectionSpace; + disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge; } } else { disposition = NSURLSessionAuthChallengePerformDefaultHandling; diff --git a/src/ios/CordovaHttpPlugin.m b/src/ios/CordovaHttpPlugin.m index cc0ef24..ecfdee3 100644 --- a/src/ios/CordovaHttpPlugin.m +++ b/src/ios/CordovaHttpPlugin.m @@ -85,7 +85,8 @@ } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [self setResults: dictionary withTask: task]; - [dictionary setObject:[error localizedDescription] forKey:@"error"]; + NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding]; + [dictionary setObject:errResponse forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; @@ -111,7 +112,8 @@ } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [self setResults: dictionary withTask: task]; - [dictionary setObject:[error localizedDescription] forKey:@"error"]; + NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding]; + [dictionary setObject:errResponse forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; @@ -137,7 +139,8 @@ } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [self setResults: dictionary withTask: task]; - [dictionary setObject:[error localizedDescription] forKey:@"error"]; + NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding]; + [dictionary setObject:errResponse forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; @@ -177,7 +180,8 @@ } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [self setResults: dictionary withTask: task]; - [dictionary setObject:[error localizedDescription] forKey:@"error"]; + NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding]; + [dictionary setObject:errResponse forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; @@ -259,7 +263,8 @@ } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; [self setResults: dictionary withTask: task]; - [dictionary setObject:[error localizedDescription] forKey:@"error"]; + NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding]; + [dictionary setObject:errResponse forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; }]; diff --git a/src/ios/TextResponseSerializer.m b/src/ios/TextResponseSerializer.m index 39d4080..1ef077c 100644 --- a/src/ios/TextResponseSerializer.m +++ b/src/ios/TextResponseSerializer.m @@ -1,10 +1,10 @@ #import "TextResponseSerializer.h" -static BOOL AFErrorOrUnderlyingErrorHasCode(NSError *error, NSInteger code) { - if (error.code == code) { +static BOOL AFErrorOrUnderlyingErrorHasCodeInDomain(NSError *error, NSInteger code, NSString *domain) { + if ([error.domain isEqualToString:domain] && error.code == code) { return YES; } else if (error.userInfo[NSUnderlyingErrorKey]) { - return AFErrorOrUnderlyingErrorHasCode(error.userInfo[NSUnderlyingErrorKey], code); + return AFErrorOrUnderlyingErrorHasCodeInDomain(error.userInfo[NSUnderlyingErrorKey], code, domain); } return NO; @@ -35,7 +35,7 @@ static BOOL AFErrorOrUnderlyingErrorHasCode(NSError *error, NSInteger code) { error:(NSError *__autoreleasing *)error { if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error]) { - if (AFErrorOrUnderlyingErrorHasCode(*error, NSURLErrorCannotDecodeContentData)) { + if (!error || AFErrorOrUnderlyingErrorHasCodeInDomain(*error, NSURLErrorCannotDecodeContentData, AFURLResponseSerializationErrorDomain)) { return nil; } }