本文介绍了如何将AFNetworking 2.0与反应性可可结合起来以将请求队列链接在一​​起?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个相互依赖的请求,我必须按顺序调用吗?
有人可以给我一个使用AFNetworking和反应性可可的例子吗?

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?

例子:


  1. LoginRequest(返回transactionId)

  2. UpdateRequest包含transactionId的数据

  3. UploadRequest jpeg具有transactionId

  4. 带有transactionId的EndRequest

  1. LoginRequest (return transactionId)
  2. UpdateRequest post data with transactionId
  3. UploadRequest jpeg with transactionId
  4. EndRequest with transactionId


推荐答案

方法名称显然是虚构的,但应该为您提供对您编写的代码形式的理解:

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];
            }];
    }]

我们正在使用 -flattenMap:获取登录请求的结果,然后再发出更多请求。

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

这篇关于如何将AFNetworking 2.0与反应性可可结合起来以将请求队列链接在一​​起?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 23:56