How-to combine AFNetworking 2.0 with reactive cocoa to chain a queue of requests together?

StackOverflow https://stackoverflow.com/questions/22100683

Question

I have several Requests that depend on each other and must me called in sequence? Can somebody give me an example using AFNetworking and reactive cocoa?

Example:

  1. LoginRequest (return transactionId)
  2. UpdateRequest post data with transactionId
  3. UploadRequest jpeg with transactionId
  4. EndRequest with transactionId
Était-ce utile?

La solution

The method names are clearly made-up but should give you a sense of the form of the code you'd write:

[[self 
    executeLoginRequest] 
    flattenMap:^(id transactionId) {
        return [[[self 
            executeUpdateRequest:data withTransactionId:transactionId] 
            then:^{
                return [self executeUploadRequest:jpeg withTransactionId:transactionId];
            }] 
            then:^{
                return [self endRequests:transactionId];
            }];
    }]

We're using -flattenMap: to take the result of the login request and then make more requests off of it.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top