Skip to content

Commit d42a0fa

Browse files
committed
Merge pull request #102 from qiniu/develop
Release 6.3.3
2 parents 477119b + be709d1 commit d42a0fa

16 files changed

+288
-183
lines changed

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,7 @@ xcode_project: QiniuSDK.xcodeproj
33
xcode_scheme: QiniuSDKTests
44
xcode_sdk:
55
- iphonesimulator7.1
6+
before_install:
7+
- brew update
8+
- brew upgrade xctool
9+
- gem install cocoapods

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## CHANGE LOG
22

3+
### v6.3.3
4+
5+
- [#101] 升级AFNetworking
6+
37
### v6.3.2
48

59
- [#94] 上传进度指示调整

QiniuSDK/AFNetworking/AFHTTPRequestOperation.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ - (void)pause {
168168
self.request = mutableURLRequest;
169169
}
170170

171-
#pragma mark - NSecureCoding
171+
#pragma mark - NSSecureCoding
172172

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

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

199199
operation.responseSerializer = [self.responseSerializer copyWithZone:zone];
200200
operation.completionQueue = self.completionQueue;

QiniuSDK/AFNetworking/AFHTTPRequestOperationManager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@
7575
7676
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.
7777
78-
## NSecureCoding & NSCopying Caveats
78+
## NSSecureCoding & NSCopying Caveats
7979
80-
`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:
80+
`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:
8181
8282
- Archives and copies of HTTP clients will be initialized with an empty operation queue.
83-
- NSecureCoding cannot serialize / deserialize block properties, so an archive of an HTTP client will not include any reachability callback block that may be set.
83+
- NSSecureCoding cannot serialize / deserialize block properties, so an archive of an HTTP client will not include any reachability callback block that may be set.
8484
*/
8585
@interface AFHTTPRequestOperationManager : NSObject <NSSecureCoding, NSCopying>
8686

QiniuSDK/AFNetworking/AFHTTPRequestOperationManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ - (NSString *)description {
213213
return [NSString stringWithFormat:@"<%@: %p, baseURL: %@, operationQueue: %@>", NSStringFromClass([self class]), self, [self.baseURL absoluteString], self.operationQueue];
214214
}
215215

216-
#pragma mark - NSecureCoding
216+
#pragma mark - NSSecureCoding
217217

218218
+ (BOOL)supportsSecureCoding {
219219
return YES;

QiniuSDK/AFNetworking/AFHTTPSessionManager.m

Lines changed: 66 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -109,71 +109,39 @@ - (NSURLSessionDataTask *)GET:(NSString *)URLString
109109
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
110110
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
111111
{
112-
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"GET" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
112+
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"GET" URLString:URLString parameters:parameters success:success failure:failure];
113113

114-
__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
115-
if (error) {
116-
if (failure) {
117-
failure(task, error);
118-
}
119-
} else {
120-
if (success) {
121-
success(task, responseObject);
122-
}
123-
}
124-
}];
114+
[dataTask resume];
125115

126-
[task resume];
127-
128-
return task;
116+
return dataTask;
129117
}
130118

131119
- (NSURLSessionDataTask *)HEAD:(NSString *)URLString
132120
parameters:(id)parameters
133121
success:(void (^)(NSURLSessionDataTask *task))success
134122
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
135123
{
136-
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"HEAD" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
137-
138-
__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id __unused responseObject, NSError *error) {
139-
if (error) {
140-
if (failure) {
141-
failure(task, error);
142-
}
143-
} else {
144-
if (success) {
145-
success(task);
146-
}
124+
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"HEAD" URLString:URLString parameters:parameters success:^(NSURLSessionDataTask *task, __unused id responseObject) {
125+
if (success) {
126+
success(task);
147127
}
148-
}];
128+
} failure:failure];
149129

150-
[task resume];
130+
[dataTask resume];
151131

152-
return task;
132+
return dataTask;
153133
}
154134

155135
- (NSURLSessionDataTask *)POST:(NSString *)URLString
156136
parameters:(id)parameters
157137
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
158138
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
159139
{
160-
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
161-
162-
__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
163-
if (error) {
164-
if (failure) {
165-
failure(task, error);
166-
}
167-
} else {
168-
if (success) {
169-
success(task, responseObject);
170-
}
171-
}
172-
}];
140+
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"POST" URLString:URLString parameters:parameters success:success failure:failure];
173141

174-
[task resume];
142+
[dataTask resume];
175143

176-
return task;
144+
return dataTask;
177145
}
178146

179147
- (NSURLSessionDataTask *)POST:(NSString *)URLString
@@ -182,7 +150,20 @@ - (NSURLSessionDataTask *)POST:(NSString *)URLString
182150
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
183151
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
184152
{
185-
NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:nil];
153+
NSError *serializationError = nil;
154+
NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError];
155+
if (serializationError) {
156+
if (failure) {
157+
#pragma clang diagnostic push
158+
#pragma clang diagnostic ignored "-Wgnu"
159+
dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
160+
failure(nil, serializationError);
161+
});
162+
#pragma clang diagnostic pop
163+
}
164+
165+
return nil;
166+
}
186167

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

211-
__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
212-
if (error) {
213-
if (failure) {
214-
failure(task, error);
215-
}
216-
} else {
217-
if (success) {
218-
success(task, responseObject);
219-
}
220-
}
221-
}];
192+
[dataTask resume];
222193

223-
[task resume];
224-
225-
return task;
194+
return dataTask;
226195
}
227196

228197
- (NSURLSessionDataTask *)PATCH:(NSString *)URLString
229198
parameters:(id)parameters
230199
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
231200
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
232201
{
233-
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"PATCH" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
234-
235-
__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
236-
if (error) {
237-
if (failure) {
238-
failure(task, error);
239-
}
240-
} else {
241-
if (success) {
242-
success(task, responseObject);
243-
}
244-
}
245-
}];
202+
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"PATCH" URLString:URLString parameters:parameters success:success failure:failure];
246203

247-
[task resume];
204+
[dataTask resume];
248205

249-
return task;
206+
return dataTask;
250207
}
251208

252209
- (NSURLSessionDataTask *)DELETE:(NSString *)URLString
253210
parameters:(id)parameters
254211
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
255212
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure
256213
{
257-
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:@"DELETE" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:nil];
214+
NSURLSessionDataTask *dataTask = [self dataTaskWithHTTPMethod:@"DELETE" URLString:URLString parameters:parameters success:success failure:failure];
215+
216+
[dataTask resume];
217+
218+
return dataTask;
219+
}
220+
221+
- (NSURLSessionDataTask *)dataTaskWithHTTPMethod:(NSString *)method
222+
URLString:(NSString *)URLString
223+
parameters:(id)parameters
224+
success:(void (^)(NSURLSessionDataTask *, id))success
225+
failure:(void (^)(NSURLSessionDataTask *, NSError *))failure
226+
{
227+
NSError *serializationError = nil;
228+
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
229+
if (serializationError) {
230+
if (failure) {
231+
#pragma clang diagnostic push
232+
#pragma clang diagnostic ignored "-Wgnu"
233+
dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
234+
failure(nil, serializationError);
235+
});
236+
#pragma clang diagnostic pop
237+
}
238+
239+
return nil;
240+
}
258241

259-
__block NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
242+
__block NSURLSessionDataTask *dataTask = nil;
243+
dataTask = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse * __unused response, id responseObject, NSError *error) {
260244
if (error) {
261245
if (failure) {
262-
failure(task, error);
246+
failure(dataTask, error);
263247
}
264248
} else {
265249
if (success) {
266-
success(task, responseObject);
250+
success(dataTask, responseObject);
267251
}
268252
}
269253
}];
270254

271-
[task resume];
272-
273-
return task;
255+
return dataTask;
274256
}
275257

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

282-
#pragma mark - NSecureCoding
264+
#pragma mark - NSSecureCoding
283265

284266
+ (BOOL)supportsSecureCoding {
285267
return YES;
@@ -291,7 +273,7 @@ - (id)initWithCoder:(NSCoder *)decoder {
291273
if (!configuration) {
292274
NSString *configurationIdentifier = [decoder decodeObjectOfClass:[NSString class] forKey:@"identifier"];
293275
if (configurationIdentifier) {
294-
#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)
276+
#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)
295277
configuration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:configurationIdentifier];
296278
#else
297279
configuration = [NSURLSessionConfiguration backgroundSessionConfiguration:configurationIdentifier];

QiniuSDK/AFNetworking/AFNetworkReachabilityManager.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
#import <Foundation/Foundation.h>
2424
#import <SystemConfiguration/SystemConfiguration.h>
2525

26-
#import <netinet/in.h>
27-
#import <netinet6/in6.h>
28-
#import <arpa/inet.h>
29-
#import <ifaddrs.h>
30-
#import <netdb.h>
31-
3226
typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
3327
AFNetworkReachabilityStatusUnknown = -1,
3428
AFNetworkReachabilityStatusNotReachable = 0,
@@ -88,11 +82,11 @@ typedef NS_ENUM(NSInteger, AFNetworkReachabilityStatus) {
8882
/**
8983
Creates and returns a network reachability manager for the socket address.
9084
91-
@param address The socket address used to evaluate network reachability.
85+
@param address The socket address (`sockaddr_in`) used to evaluate network reachability.
9286
9387
@return An initialized network reachability manager, actively monitoring the specified socket address.
9488
*/
95-
+ (instancetype)managerForAddress:(const struct sockaddr_in *)address;
89+
+ (instancetype)managerForAddress:(const void *)address;
9690

9791
/**
9892
Initializes an instance of a network reachability manager from the specified reachability object.

QiniuSDK/AFNetworking/AFNetworkReachabilityManager.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222

2323
#import "AFNetworkReachabilityManager.h"
2424

25+
#import <netinet/in.h>
26+
#import <netinet6/in6.h>
27+
#import <arpa/inet.h>
28+
#import <ifaddrs.h>
29+
#import <netdb.h>
30+
2531
NSString * const AFNetworkingReachabilityDidChangeNotification = @"com.alamofire.networking.reachability.change";
2632
NSString * const AFNetworkingReachabilityNotificationStatusItem = @"AFNetworkingReachabilityNotificationStatusItem";
2733

@@ -128,7 +134,7 @@ + (instancetype)managerForDomain:(NSString *)domain {
128134
return manager;
129135
}
130136

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

134140
AFNetworkReachabilityManager *manager = [[self alloc] initWithReachability:reachability];

QiniuSDK/AFNetworking/AFURLConnectionOperation.m

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ - (void)pause {
339339
}
340340

341341
[self.lock lock];
342-
343342
if ([self isExecuting]) {
344343
[self performSelector:@selector(operationDidPause) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
345344

@@ -350,7 +349,6 @@ - (void)pause {
350349
}
351350

352351
self.state = AFOperationPausedState;
353-
354352
[self.lock unlock];
355353
}
356354

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

467+
[self.outputStream open];
469468
[self.connection start];
470469
}
471470
[self.lock unlock];
@@ -642,8 +641,6 @@ - (void)connection:(NSURLConnection __unused *)connection
642641
didReceiveResponse:(NSURLResponse *)response
643642
{
644643
self.response = response;
645-
646-
[self.outputStream open];
647644
}
648645

649646
- (void)connection:(NSURLConnection __unused *)connection
@@ -726,7 +723,7 @@ - (NSCachedURLResponse *)connection:(NSURLConnection *)connection
726723
}
727724
}
728725

729-
#pragma mark - NSecureCoding
726+
#pragma mark - NSSecureCoding
730727

731728
+ (BOOL)supportsSecureCoding {
732729
return YES;

0 commit comments

Comments
 (0)