Skip to content

Commit

Permalink
MOD: upgrade AFNetworking version to tag: 2.5.4
Browse files Browse the repository at this point in the history
Change-Id: Icaec3ef9be3ba2b40ffbf4f25c3c4815f6952d06
Tang Qiao committed Jun 10, 2015
1 parent cf29bfe commit e35741e
Showing 38 changed files with 1,225 additions and 835 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// AFDownloadRequestOperation.h
//
// Copyright (c) 2012 Peter Steinberger (http://petersteinberger.com)
//
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -29,12 +29,12 @@
*/
@interface AFDownloadRequestOperation : AFHTTPRequestOperation

/**
/**
A String value that defines the target path or directory.
We try to be clever here and understand both a directory or a filename.
The target directory should already be create, or the download fill fail.
If the target is a directory, we use the last part of the URL as a default file name.
targetPath is the responseObject if operation succeeds
*/
@@ -46,26 +46,26 @@
*/
@property (assign) BOOL shouldOverwrite;

/**
/**
A Boolean value that indicates if we should try to resume the download. Defaults is `YES`.
Can only be set while creating the request.
*/
@property (assign, readonly) BOOL shouldResume;

/**
/**
Deletes the temporary file if operations is cancelled. Defaults to `NO`.
*/
@property (assign, getter=isDeletingTempFileOnCancel) BOOL deleteTempFileOnCancel;

/**
/**
Expected total length. This is different than expectedContentLength if the file is resumed.
Note: this can also be zero if the file size is not sent (*)
*/
@property (assign, readonly) long long totalContentLength;

/**
/**
Indicator for the file offset on partial downloads. This is greater than zero if the file download is resumed.
*/
@property (assign, readonly) long long offsetContentLength;
@@ -88,23 +88,23 @@
*/
- (id)initWithRequest:(NSURLRequest *)urlRequest targetPath:(NSString *)targetPath shouldResume:(BOOL)shouldResume;

/**
/**
Deletes the temporary file.
Returns `NO` if an error happened, `YES` if the file is removed or did not exist in the first place.
*/
- (BOOL)deleteTempFileWithError:(NSError **)error;

/**
/**
Returns the path used for the temporary file. Returns `nil` if the targetPath has not been set.
*/
- (NSString *)tempPath;

/**
Sets a callback to be called when an undetermined number of bytes have been downloaded from the server. This is a variant of setDownloadProgressBlock that adds support for progressive downloads and adds the
Sets a callback to be called when an undetermined number of bytes have been downloaded from the server. This is a variant of setDownloadProgressBlock that adds support for progressive downloads and adds the
@param block A block object to be called when an undetermined number of bytes have been downloaded from the server. This block has no return value and takes five arguments: the number of bytes read since the last time the download progress block was called, the bytes expected to be read during the request, the bytes already read during this request, the total bytes read (including from previous partial downloads), and the total bytes expected to be read for the file. This block may be called multiple times.
@see setDownloadProgressBlock
*/
- (void)setProgressiveDownloadProgressBlock:(void (^)(AFDownloadRequestOperation *operation, NSInteger bytesRead, long long totalBytesRead, long long totalBytesExpected, long long totalBytesReadForFile, long long totalBytesExpectedToReadForFile))block;
Original file line number Diff line number Diff line change
@@ -257,8 +257,6 @@ - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLRespon
totalContentLength = [bytes[3] longLongValue]; // if this is *, it's converted to 0
}
}
}else if (httpResponse.statusCode != 200){
return;
}

self.totalBytesReadPerDownload = 0;
7 changes: 3 additions & 4 deletions AFNetworking/AFHTTPRequestOperation.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// AFHTTPRequestOperation.h
//
// Copyright (c) 2013-2014 AFNetworking (http://afnetworking.com)
// Copyright (c) 2011–2015 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
@@ -40,7 +39,7 @@
/**
Responses sent from the server in data tasks created with `dataTaskWithRequest:success:failure:` and run using the `GET` / `POST` / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an AFHTTPResponse serializer, which uses the raw data as its response object. The serializer validates the status code to be in the `2XX` range, denoting success. If the response serializer generates an error in `-responseObjectForResponse:data:error:`, the `failure` callback of the session task or request operation will be executed; otherwise, the `success` callback will be executed.
@warning `responseSerializer` must not be `nil`. Setting a response serializer will clear out any cached value
@warning `responseSerializer` must not be `nil`. Setting a response serializer will clear out any cached value
*/
@property (nonatomic, strong) AFHTTPResponseSerializer <AFURLResponseSerialization> * responseSerializer;

@@ -57,7 +56,7 @@
Sets the `completionBlock` property with a block that executes either the specified success or failure block, depending on the state of the request on completion. If `error` returns a value, which can be caused by an unacceptable status code or content type, then `failure` is executed. Otherwise, `success` is executed.
This method should be overridden in subclasses in order to specify the response object passed into the success block.
@param success The block to be executed on the completion of a successful request. This block has no return value and takes two arguments: the receiver operation and the object constructed from the response data of the request.
@param failure The block to be executed on the completion of an unsuccessful request. This block has no return value and takes two arguments: the receiver operation and the error that occurred during the request.
*/
8 changes: 4 additions & 4 deletions AFNetworking/AFHTTPRequestOperation.m
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// AFHTTPRequestOperation.m
//
// Copyright (c) 2013-2014 AFNetworking (http://afnetworking.com)
// Copyright (c) 2011–2015 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
@@ -57,6 +56,7 @@ @interface AFHTTPRequestOperation ()
@end

@implementation AFHTTPRequestOperation
@dynamic response;
@dynamic lock;

- (instancetype)initWithRequest:(NSURLRequest *)urlRequest {
@@ -168,7 +168,7 @@ - (void)pause {
self.request = mutableURLRequest;
}

#pragma mark - NSecureCoding
#pragma mark - NSSecureCoding

+ (BOOL)supportsSecureCoding {
return YES;
@@ -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;
45 changes: 30 additions & 15 deletions AFNetworking/AFHTTPRequestOperationManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// AFHTTPRequestOperationManager.h
//
// Copyright (c) 2013-2014 AFNetworking (http://afnetworking.com)
// Copyright (c) 2011–2015 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
@@ -36,23 +35,31 @@
#import "AFSecurityPolicy.h"
#import "AFNetworkReachabilityManager.h"

#ifndef NS_DESIGNATED_INITIALIZER
#if __has_attribute(objc_designated_initializer)
#define NS_DESIGNATED_INITIALIZER __attribute__((objc_designated_initializer))
#else
#define NS_DESIGNATED_INITIALIZER
#endif
#endif

/**
`AFHTTPRequestOperationManager` encapsulates the common patterns of communicating with a web application over HTTP, including request creation, response serialization, network reachability monitoring, and security, as well as request operation management.
## Subclassing Notes
Developers targeting iOS 7 or Mac OS X 10.9 or later that deal extensively with a web service are encouraged to subclass `AFHTTPSessionManager`, providing a class method that returns a shared singleton object on which authentication and other configuration can be shared across the application.
For developers targeting iOS 6 or Mac OS X 10.8 or earlier, `AFHTTPRequestOperationManager` may be used to similar effect.
## Methods to Override
To change the behavior of all request operation construction for an `AFHTTPRequestOperationManager` subclass, override `HTTPRequestOperationWithRequest:success:failure`.
## Serialization
Requests created by an HTTP client will contain default headers and encode parameters according to the `requestSerializer` property, which is an object conforming to `<AFURLRequestSerialization>`.
Requests created by an HTTP client will contain default headers and encode parameters according to the `requestSerializer` property, which is an object conforming to `<AFURLRequestSerialization>`.
Responses received from the server are automatically validated and serialized by the `responseSerializers` property, which is an object conforming to `<AFURLResponseSerialization>`
## URL Construction Using Relative Paths
@@ -75,12 +82,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>

@@ -91,7 +98,7 @@

/**
Requests created with `requestWithMethod:URLString:parameters:` & `multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:` are constructed with a set of default headers using a parameter serialization specified by this property. By default, this is set to an instance of `AFHTTPRequestSerializer`, which serializes query string parameters for `GET`, `HEAD`, and `DELETE` requests, or otherwise URL-form-encodes HTTP message bodies.
@warning `requestSerializer` must not be `nil`.
*/
@property (nonatomic, strong) AFHTTPRequestSerializer <AFURLRequestSerialization> * requestSerializer;
@@ -151,12 +158,20 @@
/**
The dispatch queue for the `completionBlock` of request operations. If `NULL` (default), the main queue is used.
*/
#if OS_OBJECT_HAVE_OBJC_SUPPORT
@property (nonatomic, strong) dispatch_queue_t completionQueue;
#else
@property (nonatomic, assign) dispatch_queue_t completionQueue;
#endif

/**
The dispatch group for the `completionBlock` of request operations. If `NULL` (default), a private dispatch group is used.
*/
#if OS_OBJECT_HAVE_OBJC_SUPPORT
@property (nonatomic, strong) dispatch_group_t completionGroup;
#else
@property (nonatomic, assign) dispatch_group_t completionGroup;
#endif

///---------------------------------------------
/// @name Creating and Initializing HTTP Clients
@@ -169,14 +184,14 @@

/**
Initializes an `AFHTTPRequestOperationManager` object with the specified base URL.
This is the designated initializer.
@param url The base URL for the HTTP client.
@return The newly-initialized HTTP client
*/
- (instancetype)initWithBaseURL:(NSURL *)url;
- (instancetype)initWithBaseURL:(NSURL *)url NS_DESIGNATED_INITIALIZER;

///---------------------------------------
/// @name Managing HTTP Request Operations
Loading

0 comments on commit e35741e

Please sign in to comment.