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

不打扰是莪最后的温柔 提交于 2019-12-12 10:18:11

问题


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

回答1:


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.



来源:https://stackoverflow.com/questions/22100683/how-to-combine-afnetworking-2-0-with-reactive-cocoa-to-chain-a-queue-of-requests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!