2014-10-10 3 views
-1

AFNetworking 1.0에서 작동하는 다음 이미지 다운로드 기능이 있습니다. 그것은 AFNetworking 1.0을위한 HTTPClient 구현의 일부였습니다.AFNetworking 2.0에서 인증을 사용하여 이미지 다운로드를 구현하는 방법?

- (void)downloadImageWithCompletionBlock:(void (^)(UIImage *downloadedImage))completionBlock identifier:(NSString *)identifier { 
NSString* urlString = identifier; 

AFImageRequestOperation* operation = [AFImageRequestOperation imageRequestOperationWithRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] imageProcessingBlock:nil 
                         success:^(NSURLRequest *request, NSHTTPURLResponse *response, UIImage *image) 
             { 
              //LogInfo(@"SUCCESS GETTING PHOTO: %@", response); 
              completionBlock(image); 
             } 
                         failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error) { 

                          LogInfo(@"ERROR GETTING PHOTO IN downloadImageWithCompletionBlock."); 

                         }]; 
[operation setAuthenticationChallengeBlock:^(NSURLConnection *connection, NSURLAuthenticationChallenge *challenge) { 
    NSURLCredential *newCredential = [NSURLCredential credentialWithUser:self.strSPUser password:self.strSPPW persistence:NSURLCredentialPersistenceForSession]; 
    [challenge.sender useCredential:newCredential forAuthenticationChallenge:challenge]; 
}]; 
[self enqueueHTTPRequestOperation:operation]; 
} 

내가 쉽게 전환을 찾는 게 아니에요/I가 AFNetworking 1.0 쓴 HttpClient를 사용자 정의 코드를 AFNetworking 2.0으로 업그레이드합니다. 함수에서 볼 수 있듯이 이미지를 다운로드하기 위해 내 웹 서비스에 자격 증명을 전달하고 있습니다.

AFNetworking 2.0에서 위의 이미지 다운로드 기능을 어떻게 구현할 수 있습니까?

답변

-1

AFNetworking 2와 거의 같습니다. AFHTTPRequestOperation에는 credential 속성과 setWillSendRequestForAuthenticationChallengeBlock: 메서드가 있습니다.

+0

AFNetworking 2.0에서 어떻게 수행해야하는지에 대한 예가 있습니까? – motionpotion

+0

코드 샘플을 복사하여 붙여 넣기하고'setAuthenticationChallengeBlock'을'setWillSendRequestForAuthenticationChallengeBlock'으로 대체해야합니까? 그것은 같은 코드입니다. – mattt