2014-04-09 3 views
0

ReactiveCocoa와 Octokit.objC (github 라이브러리) 위에 앱을 만들고 있습니다. 내 노력의 일환으로 Octokits ReactiveCocoa 신호를 사용하여 인증이 필요한 리소스에 액세스합니다. 이전 질문 'Retrying an asynchronous operation using ReactiveCocoa'은 사용자가 '비동기 작업을 다시 시도'하려는 경우를 다루는 훌륭한 작업입니다. . 재 시도하려는 경우를 처리하는 방법을 알아 내려고 노력 중입니다. 여러 번 번.ReactiveCocoa로 인증하기

인증에 실패하면 특정 사용자에게 자격 증명을 요청하고 싶습니다. 나는 사용자에게 자격 증명을 몇 번 (2 또는 3) 물어보고 실패하면 중단하고 계속 성공할 때까지 자격 증명을 요청할 것입니다.

도움을 주시면 감사하겠습니다. 감사합니다 - AYAL

답변

2

카운트 매개 변수를 허용하는 -retry: 연산자가 있습니다. 이 연산자를 신호에 적용하고 해당 신호가 오류를 반환하면 오류가 수신 될 때 해당 신호를 (지정된 횟수까지) 다시 구독합니다. 따라서 구독 할 때 사용자에게 자격 증명을 묻는 신호가 필요합니다.

@weakify(self); 
RACSignal *requestCredentials = [RACSignal defer:^{ 

    @strongify(self); 

    // (Prompt the user for credentials.) 

    if (successful) 
    { 
     self.cachedCredentials = credentials; 
     return [self authenticate:credentials]; 
    } 
    else 
    { 
     return [RACSignal error:[[MyError alloc] init]]; 
    } 

}]; 

// We try to authenticate using the cached credentials (the 
// `-authenticate:` method returns a signal that attempts 
// authentication when it is subscribed to). If the initial 
// attempt to authenticate fails, we try 3 times to get the 
// user to enter the correct credentials. 
return [[self authenticate:self.cachedCredentials] 
    catchTo:[requestCredentials retry:3]]; 
관련 문제