سؤال

I have a merge operation that depends on the result of two asynchronous operations. The first is a network operation, the second is a success or failure of location authorization. I don't care about the values of these operations, just that both have completed.

This is what it looks like:

RACSignal *networkCallReturned = [[[NSNotificationCenter defaultCenter] rac_addObserverForName:kNetworkCallReturned object:nil] take:1];
RACSignal *locationPermission = [[[NSNotificationCenter defaultCenter] rac_addObserverForName:kLocationManagerGotLocationPermission object:nil] take:1];

@weakify(self);
[[RACSignal merge:@[ networkCallReturned, locationPermission ]
subscribeCompleted:^{
    @strongify(self);

    // Do something else here
}];

The problem I am having is that the network call is not made when I do not have reachability. This is not something I can change either. How can I conditionally fire the networkCallReturned signal if I do not have reachability?

Do I have to setup another signal that monitors reachability and then take the first value sent from either networkCallReturned or the reachability signal?

هل كانت مفيدة؟

المحلول

You could monitor reachability, but it's infamously fraught with races and edge cases. It seems like you'd be much better served by catching the errors that from from not being able to complete the network call, or timing out the network call.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top