Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@ xcode_project: QiniuSDK.xcodeproj
xcode_scheme: QiniuSDKTests
xcode_sdk:
- iphonesimulator7.1
before_install:
- brew update
- brew upgrade xctool
- gem install cocoapods
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## CHANGE LOG

### v6.3.3

- [#101] 升级AFNetworking

### v6.3.2

- [#94] 上传进度指示调整
Expand Down
4 changes: 2 additions & 2 deletions QiniuSDK/AFNetworking/AFHTTPRequestOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ - (void)pause {
self.request = mutableURLRequest;
}

#pragma mark - NSecureCoding
#pragma mark - NSSecureCoding

+ (BOOL)supportsSecureCoding {
return YES;
Expand All @@ -194,7 +194,7 @@ - (void)encodeWithCoder:(NSCoder *)coder {
#pragma mark - NSCopying

- (id)copyWithZone:(NSZone *)zone {
AFHTTPRequestOperation *operation = [[[self class] allocWithZone:zone] initWithRequest:self.request];
AFHTTPRequestOperation *operation = [super copyWithZone:zone];

operation.responseSerializer = [self.responseSerializer copyWithZone:zone];
operation.completionQueue = self.completionQueue;
Expand Down
6 changes: 3 additions & 3 deletions QiniuSDK/AFNetworking/AFHTTPRequestOperationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@

Network reachability status and change monitoring is available through the `reachabilityManager` property. Applications may choose to monitor network reachability conditions in order to prevent or suspend any outbound requests. See `AFNetworkReachabilityManager` for more details.

## NSecureCoding & NSCopying Caveats
## NSSecureCoding & NSCopying Caveats

`AFHTTPRequestOperationManager` conforms to the `NSecureCoding` and `NSCopying` protocols, allowing operations to be archived to disk, and copied in memory, respectively. There are a few minor caveats to keep in mind, however:
`AFHTTPRequestOperationManager` conforms to the `NSSecureCoding` and `NSCopying` protocols, allowing operations to be archived to disk, and copied in memory, respectively. There are a few minor caveats to keep in mind, however:

- Archives and copies of HTTP clients will be initialized with an empty operation queue.
- NSecureCoding cannot serialize / deserialize block properties, so an archive of an HTTP client will not include any reachability callback block that may be set.
- NSSecureCoding cannot serialize / deserialize block properties, so an archive of an HTTP client will not include any reachability callback block that may be set.
*/
@interface AFHTTPRequestOperationManager : NSObject <NSSecureCoding, NSCopying>

Expand Down
2 changes: 1 addition & 1 deletion QiniuSDK/AFNetworking/AFHTTPRequestOperationManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ - (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, baseURL: %@, operationQueue: %@>", NSStringFromClass([self class]), self, [self.baseURL absoluteString], self.operationQueue];
}

#pragma mark - NSecureCoding
#pragma mark - NSSecureCoding

+ (BOOL)supportsSecureCoding {
return YES;
Expand Down
150 changes: 66 additions & 84 deletions QiniuSDK/AFNetworking/AFHTTPSessionManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,71 +109,39 @@ - (NSURLSessionDataTask *)GET:(NSString *)URLString
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"GET" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"GET" URLString:URLString parameters:parameters success:success failure:failure];

__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
if (error) {
if (failure) {
failure(task, error);
}
} else {
if (success) {
success(task, responseObject);
}
}
}];
[dataTask resume];

[task resume];

return task;
return dataTask;
}

- (NSURLSessionDataTask *)HEAD:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(NSURLSessionDataTask *task))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"HEAD" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];

__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id __unused responseObject, NSError *error) {
if (error) {
if (failure) {
failure(task, error);
}
} else {
if (success) {
success(task);
}
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"HEAD" URLString:URLString parameters:parameters success:^(NSURLSessionDataTask *task, __unused id responseObject) {
if (success) {
success(task);
}
}];
} failure:failure];

[task resume];
[dataTask resume];

return task;
return dataTask;
}

- (NSURLSessionDataTask *)POST:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];

__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
if (error) {
if (failure) {
failure(task, error);
}
} else {
if (success) {
success(task, responseObject);
}
}
}];
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"POST" URLString:URLString parameters:parameters success:success failure:failure];

[task resume];
[dataTask resume];

return task;
return dataTask;
}

- (NSURLSessionDataTask *)POST:(NSString *)URLString
Expand All @@ -182,7 +150,20 @@ - (NSURLSessionDataTask *)POST:(NSString *)URLString
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:nil];
NSError *serializationError = nil;
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;
}

__block NSURLSessionDataTask *task = [self uploadTaskWithStreamedRequest:request progress:nil completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
if (error) {
Expand All @@ -206,71 +187,72 @@ - (NSURLSessionDataTask *)PUT:(NSString *)URLString
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"PUT" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"PUT" URLString:URLString parameters:parameters success:success failure:failure];

__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
if (error) {
if (failure) {
failure(task, error);
}
} else {
if (success) {
success(task, responseObject);
}
}
}];
[dataTask resume];

[task resume];

return task;
return dataTask;
}

- (NSURLSessionDataTask *)PATCH:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"PATCH" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];

__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
if (error) {
if (failure) {
failure(task, error);
}
} else {
if (success) {
success(task, responseObject);
}
}
}];
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"PATCH" URLString:URLString parameters:parameters success:success failure:failure];

[task resume];
[dataTask resume];

return task;
return dataTask;
}

- (NSURLSessionDataTask *)DELETE:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
{
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"DELETE" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"DELETE" URLString:URLString parameters:parameters success:success failure:failure];

[dataTask resume];

return dataTask;
}

- (NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
URLString:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(NSURLSessionDataTask *, id))success
failure:(void (^)(NSURLSessionDataTask *, NSError *))failure
{
NSError *serializationError = nil;
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;
}

__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
__block NSURLSessionDataTask *dataTask = nil;
dataTask = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
if (error) {
if (failure) {
failure(task, error);
failure(dataTask, error);
}
} else {
if (success) {
success(task, responseObject);
success(dataTask, responseObject);
}
}
}];

[task resume];

return task;
return dataTask;
}

#pragma mark - NSObject
Expand All @@ -279,7 +261,7 @@ - (NSString *)description {
return [NSString stringWithFormat:@"<%@: %p, baseURL: %@, session: %@, operationQueue: %@>", NSStringFromClass([self class]), self, [self.baseURL absoluteString], self.session, self.operationQueue];
}

#pragma mark - NSecureCoding
#pragma mark - NSSecureCoding

+ (BOOL)supportsSecureCoding {
return YES;
Expand All @@ -291,7 +273,7 @@ - (id)initWithCoder:(NSCoder *)decoder {
if (!configuration) {
NSString *configurationIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:@"identifier"];
if (configurationIdentifier) {
#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)
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 1100)
configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:configurationIdentifier];
#else
configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:configurationIdentifier];
Expand Down
10 changes: 2 additions & 8 deletions QiniuSDK/AFNetworking/AFNetworkReachabilityManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@
#import <Foundation/Foundation.h>
#import <SystemConfiguration/SystemConfiguration.h>

#import <netinet/in.h>
#import <netinet6/in6.h>
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <netdb.h>

typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
AFNetworkReachabilityStatusUnknown = -1,
AFNetworkReachabilityStatusNotReachable = 0,
Expand Down Expand Up @@ -88,11 +82,11 @@ typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
/**
Creates and returns a network reachability manager for the socket address.

@param address The socket address used to evaluate network reachability.
@param address The socket address (`sockaddr_in`) used to evaluate network reachability.

@return An initialized network reachability manager, actively monitoring the specified socket address.
*/
+ (instancetype)managerForAddress:(const struct sockaddr_in *)address;
+ (instancetype)managerForAddress:(const void *)address;

/**
Initializes an instance of a network reachability manager from the specified reachability object.
Expand Down
8 changes: 7 additions & 1 deletion QiniuSDK/AFNetworking/AFNetworkReachabilityManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@

#import "AFNetworkReachabilityManager.h"

#import <netinet/in.h>
#import <netinet6/in6.h>
#import <arpa/inet.h>
#import <ifaddrs.h>
#import <netdb.h>

NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";

Expand Down Expand Up @@ -128,7 +134,7 @@ + (instancetype)managerForDomain:(NSString *)domain {
return manager;
}

+ (instancetype)managerForAddress:(const struct sockaddr_in *)address {
+ (instancetype)managerForAddress:(const void *)address {
SCNetworkReachabilityRef reachability = SCNetworkReachabilityCreateWithAddress(kCFAllocatorDefault, (const struct sockaddr *)address);

AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];
Expand Down
7 changes: 2 additions & 5 deletions QiniuSDK/AFNetworking/AFURLConnectionOperation.m
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ - (void)pause {
}

[self.lock lock];

if ([self isExecuting]) {
[self performSelector:@selector(operationDidPause) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];

Expand All @@ -350,7 +349,6 @@ - (void)pause {
}

self.state = AFOperationPausedState;

[self.lock unlock];
}

Expand Down Expand Up @@ -466,6 +464,7 @@ - (void)operationDidStart {
[self.outputStream scheduleInRunLoop:runLoop forMode:runLoopMode];
}

[self.outputStream open];
[self.connection start];
}
[self.lock unlock];
Expand Down Expand Up @@ -642,8 +641,6 @@ - (void)connection:(NSURLConnection __unused *)connection
didReceiveResponse:(NSURLResponse *)response
{
self.response = response;

[self.outputStream open];
}

- (void)connection:(NSURLConnection __unused *)connection
Expand Down Expand Up @@ -726,7 +723,7 @@ - (NSCachedURLResponse *)connection:(NSURLConnection *)connection
}
}

#pragma mark - NSecureCoding
#pragma mark - NSSecureCoding

+ (BOOL)supportsSecureCoding {
return YES;
Expand Down
Loading