- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
如果我创建了一个管理器并实例化了,我会这样做:
AFHTTPRequestOperation *operation = [self.manager HTTPRequestOperationWithRequest:request success:mySuccessBlock failure:myFailureBlock];
[operation start];
这会在管理器的 operationQueue 上运行吗?我似乎找不到任何保证它会使用 GET、POST、PUT 方法之一来代替我假设会将操作添加到队列的方法。
我在这里看到马特的回答,但我想确定其中一种方式。
How send request with AFNetworking 2 in strict sequential order?
我想做的是排队请求并通过设置让它们同步运行
[self.manager.operationQueue setMaxConcurrentOperationCount:1];
最佳答案
如果你想在队列上运行一个操作,你必须显式地将操作添加到队列中:
AFHTTPRequestOperation *operation = [self.manager HTTPRequestOperationWithRequest:request success:mySuccessBlock failure:myFailureBlock];
[queue addOperation:operation];
这假定您将创建一个队列:
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.name = @"com.domain.app.networkQueue";
queue.maxConcurrentOperationCount = 1;
如果您只是开始操作而不将它们添加到队列中(例如 [operation start]
),它们将直接运行,而不考虑任何特定的队列参数。
请注意,您还可以将您的操作添加到操作管理器的队列中(您可以设置 maxConcurrentOperationCount
,正如您在问题中提到的那样):
[self.manager.operationQueue addOperation:operation];
这使您不必创建自己的队列。但它随后假定您对该 manager
的所有其他 AFNetworking 请求也将连续运行。就个人而言,我会单独留下 manager.operationQueue
,并为我需要串行操作的逻辑创建一个专用队列。
最后一点:使用串行网络操作会对并发请求造成显着的性能损失。我会根据您的问题假设您绝对需要连续执行此操作,但总的来说,我现在设计我的应用程序以尽可能使用并发请求,因为它是一个更好的用户体验。如果我需要串行执行特定操作(例如登录),那么我会使用操作依赖项或完成 block 来执行此操作,但应用程序的其余部分会尽可能运行并发网络请求。
关于ios - AFHTTPRequestOperationManager 是否在 operationQueue 上运行请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21978951/
在我的应用程序中,我应该下载一些 JSON 文件,然后我将这些 URL 存储在一个 plist 中,正如您在我的代码中看到的那样。在我创建一个“AFHTTPRequestOperationManage
我正在使用 AFNetworking 套件开发 iOS 应用。 当应用程序启动时,它会从服务器请求访问 token 。 代码很简单: __block int status = 0; [manager
AFHTTPRequestOperationManager 总是默认或以其他方式给出缓存响应。 有人知道如何解决这个问题吗? 最佳答案 您可以使用: [[[AFHTTPRequestOperation
我正在使用 AFHTTPRequestOperationManager 来实现我的网络功能。在执行网络请求之前,有什么方法可以知道该请求是否会从缓存中得到满足? 最佳答案 你可以试试 cachedRe
我的代码在这里: AFHTTPRequestOperationManager *managers = [AFHTTPRequestOperationManager manager]; NSMutabl
我正在使用 AFHTTPRequestOperationManager 将一些 JSON 发布到我的服务器,我的代码如下。 NSDictionary *parameters = [[NSDiction
我正在使用 AFNetworking对于我在我的应用程序中的所有连接。我创建了一个单独的“客户端”类来处理所有 AFNetworking代码和用途 AFHTTPRequestOperationMana
我是 objective-c 的完全菜鸟,所以请原谅这个愚蠢的问题。 我已经能够按照 AFNetworking 2.0 的指南使用 AFHTTPRequestOperationManager 发送帖子
我正在使用以下代码来设置我的运营管理器: requestSerializerJson = [AFJSONRequestSerializer serializer]; [requestSerialize
我正在使用 AFHTTPRequestOperationManager 进行登录。 - (IBAction)loginAction { [TGProjectHandler clearCooki
我正在使用 AFNetworking 2.0 向返回 JSON 数据的网络服务发出 POST 请求。 { post = { "first_name" = Joe
首先使用 AFHTTPRequestOperationManager 调用“post 方法”,它的工作正常。但是我第二次为同一个 AFHTTPRequestOperationManager 调用 ge
我正在从一个非常慢的服务器下载 JSON 数据。从服务器获得响应大约需要一分钟。我使用 AFNetworking 库,我的代码抛出“请求超时”错误: NSString *urlString = [NS
我正在使用 afnetworking 2.0 加载 json: NSString *weatherUrl = @"http://www.souche.com/pages/xx/xx.json?requ
我正在尝试使用 afnetworking 将相机拍摄的照片上传到网络服务。 这是我的上传部分代码: CGSize newSize = CGSizeMake(500.0f, 500.0f); UIGra
我正在尝试使用在登录时返回 ASPXAUTH cookie 的 .NET 服务器。当我与 Charles 一起观察网络流量时,我肯定会恢复 cookie,但是当我检查 [NSHTTPCookieSto
我创建了一个 AFHTTPRequestOperationManager 的子类,并希望将超时设置为 3 秒。 [netMgr.requestSerializer setTimeoutInterval
我有一个网络服务需要 Content-Type = application/x-www-form-urlencoded。我已经设置了 header ,但它并没有像我在请求日志中看到的那样改变。下面是代
如果我创建了一个管理器并实例化了,我会这样做: AFHTTPRequestOperation *operation = [self.manager HTTPRequestOperationWithRe
我的服务器端是使用 DJango 服务作为 API 的谷歌计算引擎 这是我在 xcode IOS 6.1 中运行的代码 static NSString *const BaseURLString = @
我是一名优秀的程序员,十分优秀!