Fixes SecTrustCreateWithCertificates expecting an array as first argument.
This commit is contained in:
parent
a0f1f83a2b
commit
8b2d01a503
1 changed files with 61 additions and 56 deletions
|
|
@ -174,7 +174,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
_networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil];
|
_networkRequestThread = [[NSThread alloc] initWithTarget:self selector:@selector(networkRequestThreadEntryPoint:) object:nil];
|
||||||
[_networkRequestThread start];
|
[_networkRequestThread start];
|
||||||
});
|
});
|
||||||
|
|
||||||
return _networkRequestThread;
|
return _networkRequestThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -185,7 +185,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
dispatch_once(&onceToken, ^{
|
dispatch_once(&onceToken, ^{
|
||||||
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
|
NSBundle *bundle = [NSBundle bundleForClass:[self class]];
|
||||||
NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"."];
|
NSArray *paths = [bundle pathsForResourcesOfType:@"cer" inDirectory:@"."];
|
||||||
|
|
||||||
NSMutableArray *certificates = [NSMutableArray arrayWithCapacity:[paths count]];
|
NSMutableArray *certificates = [NSMutableArray arrayWithCapacity:[paths count]];
|
||||||
for (NSString *path in paths) {
|
for (NSString *path in paths) {
|
||||||
NSData *certificateData = [NSData dataWithContentsOfFile:path];
|
NSData *certificateData = [NSData dataWithContentsOfFile:path];
|
||||||
|
|
@ -194,7 +194,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
|
|
||||||
_pinnedCertificates = [[NSArray alloc] initWithArray:certificates];
|
_pinnedCertificates = [[NSArray alloc] initWithArray:certificates];
|
||||||
});
|
});
|
||||||
|
|
||||||
return _pinnedCertificates;
|
return _pinnedCertificates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -208,7 +208,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
for (NSData *data in pinnedCertificates) {
|
for (NSData *data in pinnedCertificates) {
|
||||||
SecCertificateRef allowedCertificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)data);
|
SecCertificateRef allowedCertificate = SecCertificateCreateWithData(NULL, (__bridge CFDataRef)data);
|
||||||
NSCParameterAssert(allowedCertificate);
|
NSCParameterAssert(allowedCertificate);
|
||||||
|
|
||||||
SecCertificateRef allowedCertificates[] = {allowedCertificate};
|
SecCertificateRef allowedCertificates[] = {allowedCertificate};
|
||||||
CFArrayRef certificates = CFArrayCreate(NULL, (const void **)allowedCertificates, 1, NULL);
|
CFArrayRef certificates = CFArrayCreate(NULL, (const void **)allowedCertificates, 1, NULL);
|
||||||
|
|
||||||
|
|
@ -219,13 +219,13 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
|
|
||||||
SecKeyRef allowedPublicKey = SecTrustCopyPublicKey(allowedTrust);
|
SecKeyRef allowedPublicKey = SecTrustCopyPublicKey(allowedTrust);
|
||||||
[publicKeys addObject:(__bridge_transfer id)allowedPublicKey];
|
[publicKeys addObject:(__bridge_transfer id)allowedPublicKey];
|
||||||
|
|
||||||
CFRelease(allowedTrust);
|
CFRelease(allowedTrust);
|
||||||
CFRelease(policy);
|
CFRelease(policy);
|
||||||
CFRelease(certificates);
|
CFRelease(certificates);
|
||||||
CFRelease(allowedCertificate);
|
CFRelease(allowedCertificate);
|
||||||
}
|
}
|
||||||
|
|
||||||
_pinnedPublicKeys = [[NSArray alloc] initWithArray:publicKeys];
|
_pinnedPublicKeys = [[NSArray alloc] initWithArray:publicKeys];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -238,20 +238,20 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
if (!self) {
|
if (!self) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.lock = [[NSRecursiveLock alloc] init];
|
self.lock = [[NSRecursiveLock alloc] init];
|
||||||
self.lock.name = kAFNetworkingLockName;
|
self.lock.name = kAFNetworkingLockName;
|
||||||
|
|
||||||
self.runLoopModes = [NSSet setWithObject:NSRunLoopCommonModes];
|
self.runLoopModes = [NSSet setWithObject:NSRunLoopCommonModes];
|
||||||
|
|
||||||
self.request = urlRequest;
|
self.request = urlRequest;
|
||||||
|
|
||||||
self.shouldUseCredentialStorage = YES;
|
self.shouldUseCredentialStorage = YES;
|
||||||
|
|
||||||
self.outputStream = [NSOutputStream outputStreamToMemory];
|
self.outputStream = [NSOutputStream outputStreamToMemory];
|
||||||
|
|
||||||
self.state = AFOperationReadyState;
|
self.state = AFOperationReadyState;
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -260,7 +260,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
[_outputStream close];
|
[_outputStream close];
|
||||||
_outputStream = nil;
|
_outputStream = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
|
#if defined(__IPHONE_OS_VERSION_MIN_REQUIRED)
|
||||||
if (_backgroundTaskIdentifier) {
|
if (_backgroundTaskIdentifier) {
|
||||||
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskIdentifier];
|
[[UIApplication sharedApplication] endBackgroundTask:_backgroundTaskIdentifier];
|
||||||
|
|
@ -281,7 +281,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
__weak __typeof(&*self)weakSelf = self;
|
__weak __typeof(&*self)weakSelf = self;
|
||||||
[super setCompletionBlock:^ {
|
[super setCompletionBlock:^ {
|
||||||
__strong __typeof(&*weakSelf)strongSelf = weakSelf;
|
__strong __typeof(&*weakSelf)strongSelf = weakSelf;
|
||||||
|
|
||||||
block();
|
block();
|
||||||
[strongSelf setCompletionBlock:nil];
|
[strongSelf setCompletionBlock:nil];
|
||||||
}];
|
}];
|
||||||
|
|
@ -305,7 +305,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
if (outputStream == _outputStream) {
|
if (outputStream == _outputStream) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self willChangeValueForKey:@"outputStream"];
|
[self willChangeValueForKey:@"outputStream"];
|
||||||
if (_outputStream) {
|
if (_outputStream) {
|
||||||
[_outputStream close];
|
[_outputStream close];
|
||||||
|
|
@ -322,14 +322,14 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
__weak __typeof(&*self)weakSelf = self;
|
__weak __typeof(&*self)weakSelf = self;
|
||||||
self.backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{
|
self.backgroundTaskIdentifier = [application beginBackgroundTaskWithExpirationHandler:^{
|
||||||
__strong __typeof(&*weakSelf)strongSelf = weakSelf;
|
__strong __typeof(&*weakSelf)strongSelf = weakSelf;
|
||||||
|
|
||||||
if (handler) {
|
if (handler) {
|
||||||
handler();
|
handler();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (strongSelf) {
|
if (strongSelf) {
|
||||||
[strongSelf cancel];
|
[strongSelf cancel];
|
||||||
|
|
||||||
[application endBackgroundTask:strongSelf.backgroundTaskIdentifier];
|
[application endBackgroundTask:strongSelf.backgroundTaskIdentifier];
|
||||||
strongSelf.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
|
strongSelf.backgroundTaskIdentifier = UIBackgroundTaskInvalid;
|
||||||
}
|
}
|
||||||
|
|
@ -386,7 +386,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
self.responseString = [[NSString alloc] initWithData:self.responseData encoding:self.responseStringEncoding];
|
self.responseString = [[NSString alloc] initWithData:self.responseData encoding:self.responseStringEncoding];
|
||||||
}
|
}
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
|
|
||||||
return _responseString;
|
return _responseString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -400,11 +400,11 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
stringEncoding = CFStringConvertEncodingToNSStringEncoding(IANAEncoding);
|
stringEncoding = CFStringConvertEncodingToNSStringEncoding(IANAEncoding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.responseStringEncoding = stringEncoding;
|
self.responseStringEncoding = stringEncoding;
|
||||||
}
|
}
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
|
|
||||||
return _responseStringEncoding;
|
return _responseStringEncoding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -412,20 +412,20 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
if ([self isPaused] || [self isFinished] || [self isCancelled]) {
|
if ([self isPaused] || [self isFinished] || [self isCancelled]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.lock lock];
|
[self.lock lock];
|
||||||
|
|
||||||
if ([self isExecuting]) {
|
if ([self isExecuting]) {
|
||||||
[self.connection performSelector:@selector(cancel) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
[self.connection performSelector:@selector(cancel) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
|
||||||
[notificationCenter postNotificationName:AFNetworkingOperationDidFinishNotification object:self];
|
[notificationCenter postNotificationName:AFNetworkingOperationDidFinishNotification object:self];
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state = AFOperationPausedState;
|
self.state = AFOperationPausedState;
|
||||||
|
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -437,10 +437,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
if (![self isPaused]) {
|
if (![self isPaused]) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[self.lock lock];
|
[self.lock lock];
|
||||||
self.state = AFOperationReadyState;
|
self.state = AFOperationReadyState;
|
||||||
|
|
||||||
[self start];
|
[self start];
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
}
|
}
|
||||||
|
|
@ -467,7 +467,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
[self.lock lock];
|
[self.lock lock];
|
||||||
if ([self isReady]) {
|
if ([self isReady]) {
|
||||||
self.state = AFOperationExecutingState;
|
self.state = AFOperationExecutingState;
|
||||||
|
|
||||||
[self performSelector:@selector(operationDidStart) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
[self performSelector:@selector(operationDidStart) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
||||||
}
|
}
|
||||||
[self.lock unlock];
|
[self.lock unlock];
|
||||||
|
|
@ -512,7 +512,7 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
_cancelled = YES;
|
_cancelled = YES;
|
||||||
[super cancel];
|
[super cancel];
|
||||||
[self didChangeValueForKey:@"isCancelled"];
|
[self didChangeValueForKey:@"isCancelled"];
|
||||||
|
|
||||||
// Cancel the connection on the thread it runs on to prevent race conditions
|
// Cancel the connection on the thread it runs on to prevent race conditions
|
||||||
[self performSelector:@selector(cancelConnection) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
[self performSelector:@selector(cancelConnection) onThread:[[self class] networkRequestThread] withObject:nil waitUntilDone:NO modes:[self.runLoopModes allObjects]];
|
||||||
}
|
}
|
||||||
|
|
@ -525,10 +525,10 @@ static inline BOOL AFStateTransitionIsValid(AFOperationState fromState, AFOperat
|
||||||
userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
userInfo = [NSDictionary dictionaryWithObject:[self.request URL] forKey:NSURLErrorFailingURLErrorKey];
|
||||||
}
|
}
|
||||||
self.error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo];
|
self.error = [NSError errorWithDomain:NSURLErrorDomain code:NSURLErrorCancelled userInfo:userInfo];
|
||||||
|
|
||||||
if (self.connection) {
|
if (self.connection) {
|
||||||
[self.connection cancel];
|
[self.connection cancel];
|
||||||
|
|
||||||
// Manually send this delegate message since `[self.connection cancel]` causes the connection to never send another message to its delegate
|
// Manually send this delegate message since `[self.connection cancel]` causes the connection to never send another message to its delegate
|
||||||
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.error];
|
[self performSelector:@selector(connection:didFailWithError:) withObject:self.connection withObject:self.error];
|
||||||
}
|
}
|
||||||
|
|
@ -553,13 +553,18 @@ willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challe
|
||||||
if (self.SSLPinningMode == AFSSLPinningModeCertificate) {
|
if (self.SSLPinningMode == AFSSLPinningModeCertificate) {
|
||||||
[trustChain addObject:(__bridge_transfer NSData *)SecCertificateCopyData(certificate)];
|
[trustChain addObject:(__bridge_transfer NSData *)SecCertificateCopyData(certificate)];
|
||||||
} else if (self.SSLPinningMode == AFSSLPinningModePublicKey) {
|
} else if (self.SSLPinningMode == AFSSLPinningModePublicKey) {
|
||||||
|
SecCertificateRef someCertificates[] = {certificate};
|
||||||
|
CFArrayRef certificates = CFArrayCreate(NULL, (const void **)someCertificates, 1, NULL);
|
||||||
|
|
||||||
SecTrustRef trust = NULL;
|
SecTrustRef trust = NULL;
|
||||||
OSStatus status = SecTrustCreateWithCertificates(certificate, policy, &trust);
|
|
||||||
|
OSStatus status = SecTrustCreateWithCertificates(certificates, policy, &trust);
|
||||||
NSAssert(status == noErr, @"SecTrustCreateWithCertificates error: %ld", (long int)status);
|
NSAssert(status == noErr, @"SecTrustCreateWithCertificates error: %ld", (long int)status);
|
||||||
|
|
||||||
[trustChain addObject:(__bridge_transfer id)SecTrustCopyPublicKey(trust)];
|
[trustChain addObject:(__bridge_transfer id)SecTrustCopyPublicKey(trust)];
|
||||||
|
|
||||||
CFRelease(trust);
|
CFRelease(trust);
|
||||||
|
CFRelease(certificates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -622,7 +627,7 @@ canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (self.authenticationAgainstProtectionSpace) {
|
if (self.authenticationAgainstProtectionSpace) {
|
||||||
return self.authenticationAgainstProtectionSpace(connection, protectionSpace);
|
return self.authenticationAgainstProtectionSpace(connection, protectionSpace);
|
||||||
} else if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] || [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]) {
|
} else if ([protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust] || [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodClientCertificate]) {
|
||||||
|
|
@ -641,16 +646,16 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (self.authenticationChallenge) {
|
if (self.authenticationChallenge) {
|
||||||
self.authenticationChallenge(connection, challenge);
|
self.authenticationChallenge(connection, challenge);
|
||||||
} else {
|
} else {
|
||||||
if ([challenge previousFailureCount] == 0) {
|
if ([challenge previousFailureCount] == 0) {
|
||||||
NSURLCredential *credential = nil;
|
NSURLCredential *credential = nil;
|
||||||
|
|
||||||
NSString *user = [[self.request URL] user];
|
NSString *user = [[self.request URL] user];
|
||||||
NSString *password = [[self.request URL] password];
|
NSString *password = [[self.request URL] password];
|
||||||
|
|
||||||
if (user && password) {
|
if (user && password) {
|
||||||
credential = [NSURLCredential credentialWithUser:user password:password persistence:NSURLCredentialPersistenceNone];
|
credential = [NSURLCredential credentialWithUser:user password:password persistence:NSURLCredentialPersistenceNone];
|
||||||
} else if (user) {
|
} else if (user) {
|
||||||
|
|
@ -658,11 +663,11 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||||
} else {
|
} else {
|
||||||
credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[challenge protectionSpace]];
|
credential = [[NSURLCredentialStorage sharedCredentialStorage] defaultCredentialForProtectionSpace:[challenge protectionSpace]];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!credential) {
|
if (!credential) {
|
||||||
credential = self.credential;
|
credential = self.credential;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (credential) {
|
if (credential) {
|
||||||
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
|
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -684,7 +689,7 @@ didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
|
||||||
if ([request.HTTPBodyStream conformsToProtocol:@protocol(NSCopying)]) {
|
if ([request.HTTPBodyStream conformsToProtocol:@protocol(NSCopying)]) {
|
||||||
return [request.HTTPBodyStream copy];
|
return [request.HTTPBodyStream copy];
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -715,7 +720,7 @@ totalBytesExpectedToWrite:(NSInteger)totalBytesExpectedToWrite
|
||||||
didReceiveResponse:(NSURLResponse *)response
|
didReceiveResponse:(NSURLResponse *)response
|
||||||
{
|
{
|
||||||
self.response = response;
|
self.response = response;
|
||||||
|
|
||||||
[self.outputStream open];
|
[self.outputStream open];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -738,11 +743,11 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
|
|
||||||
- (void)connectionDidFinishLoading:(NSURLConnection __unused *)connection {
|
- (void)connectionDidFinishLoading:(NSURLConnection __unused *)connection {
|
||||||
self.responseData = [self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
|
self.responseData = [self.outputStream propertyForKey:NSStreamDataWrittenToMemoryStreamKey];
|
||||||
|
|
||||||
[self.outputStream close];
|
[self.outputStream close];
|
||||||
|
|
||||||
[self finish];
|
[self finish];
|
||||||
|
|
||||||
self.connection = nil;
|
self.connection = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -750,11 +755,11 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
didFailWithError:(NSError *)error
|
didFailWithError:(NSError *)error
|
||||||
{
|
{
|
||||||
self.error = error;
|
self.error = error;
|
||||||
|
|
||||||
[self.outputStream close];
|
[self.outputStream close];
|
||||||
|
|
||||||
[self finish];
|
[self finish];
|
||||||
|
|
||||||
self.connection = nil;
|
self.connection = nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -767,7 +772,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
if ([self isCancelled]) {
|
if ([self isCancelled]) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return cachedResponse;
|
return cachedResponse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -776,27 +781,27 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
|
|
||||||
- (id)initWithCoder:(NSCoder *)aDecoder {
|
- (id)initWithCoder:(NSCoder *)aDecoder {
|
||||||
NSURLRequest *request = [aDecoder decodeObjectForKey:@"request"];
|
NSURLRequest *request = [aDecoder decodeObjectForKey:@"request"];
|
||||||
|
|
||||||
self = [self initWithRequest:request];
|
self = [self initWithRequest:request];
|
||||||
if (!self) {
|
if (!self) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
self.state = (AFOperationState)[aDecoder decodeIntegerForKey:@"state"];
|
self.state = (AFOperationState)[aDecoder decodeIntegerForKey:@"state"];
|
||||||
self.cancelled = [aDecoder decodeBoolForKey:@"isCancelled"];
|
self.cancelled = [aDecoder decodeBoolForKey:@"isCancelled"];
|
||||||
self.response = [aDecoder decodeObjectForKey:@"response"];
|
self.response = [aDecoder decodeObjectForKey:@"response"];
|
||||||
self.error = [aDecoder decodeObjectForKey:@"error"];
|
self.error = [aDecoder decodeObjectForKey:@"error"];
|
||||||
self.responseData = [aDecoder decodeObjectForKey:@"responseData"];
|
self.responseData = [aDecoder decodeObjectForKey:@"responseData"];
|
||||||
self.totalBytesRead = [[aDecoder decodeObjectForKey:@"totalBytesRead"] longLongValue];
|
self.totalBytesRead = [[aDecoder decodeObjectForKey:@"totalBytesRead"] longLongValue];
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
- (void)encodeWithCoder:(NSCoder *)aCoder {
|
||||||
[self pause];
|
[self pause];
|
||||||
|
|
||||||
[aCoder encodeObject:self.request forKey:@"request"];
|
[aCoder encodeObject:self.request forKey:@"request"];
|
||||||
|
|
||||||
switch (self.state) {
|
switch (self.state) {
|
||||||
case AFOperationExecutingState:
|
case AFOperationExecutingState:
|
||||||
case AFOperationPausedState:
|
case AFOperationPausedState:
|
||||||
|
|
@ -806,7 +811,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
[aCoder encodeInteger:self.state forKey:@"state"];
|
[aCoder encodeInteger:self.state forKey:@"state"];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
[aCoder encodeBool:[self isCancelled] forKey:@"isCancelled"];
|
[aCoder encodeBool:[self isCancelled] forKey:@"isCancelled"];
|
||||||
[aCoder encodeObject:self.response forKey:@"response"];
|
[aCoder encodeObject:self.response forKey:@"response"];
|
||||||
[aCoder encodeObject:self.error forKey:@"error"];
|
[aCoder encodeObject:self.error forKey:@"error"];
|
||||||
|
|
@ -818,7 +823,7 @@ didReceiveResponse:(NSURLResponse *)response
|
||||||
|
|
||||||
- (id)copyWithZone:(NSZone *)zone {
|
- (id)copyWithZone:(NSZone *)zone {
|
||||||
AFURLConnectionOperation *operation = [(AFURLConnectionOperation *)[[self class] allocWithZone:zone] initWithRequest:self.request];
|
AFURLConnectionOperation *operation = [(AFURLConnectionOperation *)[[self class] allocWithZone:zone] initWithRequest:self.request];
|
||||||
|
|
||||||
operation.uploadProgress = self.uploadProgress;
|
operation.uploadProgress = self.uploadProgress;
|
||||||
operation.downloadProgress = self.downloadProgress;
|
operation.downloadProgress = self.downloadProgress;
|
||||||
operation.authenticationAgainstProtectionSpace = self.authenticationAgainstProtectionSpace;
|
operation.authenticationAgainstProtectionSpace = self.authenticationAgainstProtectionSpace;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue