Adding responseStringEncoding property to AFURLConnectionOperation
This commit is contained in:
parent
eaa1252d40
commit
607e91b5b8
2 changed files with 21 additions and 4 deletions
|
|
@ -114,11 +114,16 @@
|
|||
|
||||
/**
|
||||
The string representation of the response data.
|
||||
|
||||
@discussion This method uses the string encoding of the response, or if UTF-8 if not specified, to construct a string from the response data.
|
||||
*/
|
||||
@property (readonly, nonatomic, copy) NSString *responseString;
|
||||
|
||||
/**
|
||||
The string encoding of the response.
|
||||
|
||||
@discussion If the response does not specify a valid string encoding, `responseStringEncoding` will return `NSUTF8StringEncoding`.
|
||||
*/
|
||||
@property (readonly, nonatomic, assign) NSStringEncoding responseStringEncoding;
|
||||
|
||||
///------------------------
|
||||
/// @name Accessing Streams
|
||||
///------------------------
|
||||
|
|
|
|||
|
|
@ -115,6 +115,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
|||
@property (readwrite, nonatomic, strong) NSError *error;
|
||||
@property (readwrite, nonatomic, strong) NSData *responseData;
|
||||
@property (readwrite, nonatomic, copy) NSString *responseString;
|
||||
@property (readwrite, nonatomic, assign) NSStringEncoding responseStringEncoding;
|
||||
@property (readwrite, nonatomic, assign) long long totalBytesRead;
|
||||
@property (readwrite, nonatomic, assign) AFBackgroundTaskIdentifier backgroundTaskIdentifier;
|
||||
@property (readwrite, nonatomic, copy) AFURLConnectionOperationProgressBlock uploadProgress;
|
||||
|
|
@ -139,6 +140,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
|||
@synthesize error = _error;
|
||||
@synthesize responseData = _responseData;
|
||||
@synthesize responseString = _responseString;
|
||||
@synthesize responseStringEncoding = _responseStringEncoding;
|
||||
@synthesize totalBytesRead = _totalBytesRead;
|
||||
@dynamic inputStream;
|
||||
@synthesize outputStream = _outputStream;
|
||||
|
|
@ -326,6 +328,16 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
|||
- (NSString *)responseString {
|
||||
[self.lock lock];
|
||||
if (!_responseString && self.response && self.responseData) {
|
||||
self.responseString = [[NSString alloc] initWithData:self.responseData encoding:self.responseStringEncoding];
|
||||
}
|
||||
[self.lock unlock];
|
||||
|
||||
return _responseString;
|
||||
}
|
||||
|
||||
- (NSStringEncoding)responseStringEncoding {
|
||||
[self.lock lock];
|
||||
if (!_responseStringEncoding) {
|
||||
NSStringEncoding stringEncoding = NSUTF8StringEncoding;
|
||||
if (self.response.textEncodingName) {
|
||||
CFStringEncoding IANAEncoding = CFStringConvertIANACharSetNameToEncoding((__bridge CFStringRef)self.response.textEncodingName);
|
||||
|
|
@ -334,11 +346,11 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
|||
}
|
||||
}
|
||||
|
||||
self.responseString = [[NSString alloc] initWithData:self.responseData encoding:stringEncoding];
|
||||
self.responseStringEncoding = stringEncoding;
|
||||
}
|
||||
[self.lock unlock];
|
||||
|
||||
return _responseString;
|
||||
return _responseStringEncoding;
|
||||
}
|
||||
|
||||
- (void)pause {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue