Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用ReactiveCocoa进行身份验证_Ios_Reactive Cocoa - Fatal编程技术网

Ios 使用ReactiveCocoa进行身份验证

Ios 使用ReactiveCocoa进行身份验证,ios,reactive-cocoa,Ios,Reactive Cocoa,我正在ReactiveCocoa和Octokit.objC(github库)之上构建一个应用程序。作为我工作的一部分,我使用Octokits ReactiveCocoa信号来访问需要身份验证的资源。前面的问题“”很好地解决了用户希望“重试异步操作”一次的情况。我试图找出如何处理您可能希望重试几次的情况 在我的特定情况下,如果身份验证失败,我想向用户询问他们的凭据。我会多次(2次或3次)向用户询问他们的凭据,如果他们失败,我会停止,或者我会一直向他们询问凭据,直到他们成功为止 任何帮助都将不胜感激

我正在ReactiveCocoa和Octokit.objC(github库)之上构建一个应用程序。作为我工作的一部分,我使用Octokits ReactiveCocoa信号来访问需要身份验证的资源。前面的问题“”很好地解决了用户希望“重试异步操作”一次的情况。我试图找出如何处理您可能希望重试几次的情况

在我的特定情况下,如果身份验证失败,我想向用户询问他们的凭据。我会多次(2次或3次)向用户询问他们的凭据,如果他们失败,我会停止,或者我会一直向他们询问凭据,直到他们成功为止


任何帮助都将不胜感激。谢谢-AYAL

有一个名为
-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]];