2

在我的项目中使用 AFNetworking 时遇到了一些问题。让我们来看看:

NSOperationQueue* queue = [[NSOperationQueue alloc] init];

AFJSONRequestOperation* op1 = [self operationSyncLeagues]; //URL=http://pm[dot]mvdigital[dot]vn/sandbox/zozo/smartphone.php?lastsynced=1340362261&task=league.listall_syncable&session_id=1946a6504e90f80cb3bd21fb90b0be85

AFJSONRequestOperation* op2 =[self operationSyncMatches]; // URL = http://pm[dot]mvdigital[dot]vn/sandbox/zozo/smartphone.php?pagesize=10&session_id=1946a6504e90f80cb3bd21fb90b0be85&page=1&league_id=51&lastsynced=1340362314&task=match.schedule_syncable

[queue setMaxConcurrentOperationCount:4];
[queue addOperations:[NSArray arrayWithObjects: op1, op2, nil] waitUntilFinished:NO];

现在,让我们看看我的日志(我在 AFURLConnectionOperation.m 中放了一些 NSLog 用于调试):

2个操作同时开始。美好的!

2012-06-26 00:28:21.688 zozo[11726:18d03] * [开始] URL:http://pm[dot]mvdigital[dot]vn/sandbox/zozo/smartphone.php?lastsynced=1340362261&task=league。 listall_syncable&session_id=1946a6504e90f80cb3bd21fb90b0be85

2012-06-26 00:28:21.689 zozo[11726:18d03] * [开始] URL: http://pm[dot]mvdigital[dot]vn/sandbox/zozo/smartphone.php?pagesize=10&session_id=1946a6504e90f80cb3bd21fb90b0be85&page= 1&league_id=51&lastsynced=1340362314&task=match.schedule_syncable

没有重定向,但为什么会触发 willSendRequest?可以检查我的 API 的 url 以了解详细信息

2012-06-26 00:28:21.689 zozo[11726:18d03] willSendRequest [redirectResponse 描述]:(null) 2012-06-26 00:28:21.690 zozo[11726:18d03] willSendRequest [redirectResponse 描述]:(null)

2012-06-26 00:28:21.913 zozo[11726:18d03] * [90 bytes] URL: http://pm[dot]mvdigital[dot]vn/sandbox/zozo/smartphone.php?lastsynced=1340362261&task=league .listall_syncable&session_id=1946a6504e90f80cb3bd21fb90b0be85

2012-06-26 00:28:21.913 zozo[11726:18d03] * [完成] URL:http://pm[dot]mvdigital[dot]vn/sandbox/zozo/smartphone.php?lastsynced=1340362261&task=league。 listall_syncable&session_id=1946a6504e90f80cb3bd21fb90b0be85

2012-06-26 00:28:21 .914 zozo[11726:15203] 同步联赛成功

操作 1 完成但操作 2 在 5 秒后开始获取数据。为什么?

2012-06-26 00:28:26 .421 zozo[11726:18d03] * [92 bytes] URL: http://pm[dot]mvdigital[dot]vn/sandbox/zozo/smartphone.php?pagesize=10&session_id =1946a6504e90f80cb3bd21fb90b0be85&page=1&league_id=51&lastsynced=1340362314&task=match.schedule_syncable

2012-06-26 00:28:26.422 zozo[11726:18d03] * [完成] URL: http://pm[dot]mvdigital[dot]vn/sandbox/zozo/smartphone.php?pagesize=10&session_id=1946a6504e90f80cb3bd21fb90b0be85&page= 1&league_id=51&lastsynced=1340362314&task=match.schedule_syncable

2012-06-26 00:28:26.423 zozo[11726:15203] 同步匹配成功

来自 AFNetworking 文档:“另一种选择是利用 AFJSONRequestOperation 与 AFNetworking 中的所有请求操作一样是 NSOperation 的子类这一事实。结合 NSOperationQueue,您可以轻松地同时运行多个请求(您有能够设置同时运行的最大操作数,以防止您的网络陷入困境)。”

<== 那么这里有什么问题呢?我刚收到 2 个请求(每个 92 个字节),我不能让它们像同时运行一样。这里有任何错误吗?

p/s:我已经尝试使用 sharedclient 使用 AFHTTPClient,但我没有运气。我的服务器很好,我的 Android 客户端没有任何问题有人遇到同样的问题吗?并发请求数是否有任何限制?

http://pm[dot]mvdigital[dot]vn/ <== http://pm.mvdigital.vn/

谢谢。

编辑:

我自己找到了答案,点击这里:http: //github.com/AFNetworking/AFNetworking/issues/387

4

0 回答 0