AFNetworking + NSOperation与并发请求有关

时间:2012-06-26 02:59:25

标签: ios nsoperationqueue afnetworking

在我的项目中使用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] * [START]网址:http:// pm [dot] mvdigital [dot] vn / sandbox / zozo / smartphone.php lastsynced = 1340362261&安培;任务= league.listall_syncable&安培; SESSION_ID = 1946a6504e90f80cb3bd21fb90b0be85

2012-06-26 00:28:21.689 zozo [11726:18d03] * [START]网址:http:// pm [dot] mvdigital [dot] vn / sandbox / zozo / smartphone.php页大小= 10&安培; SESSION_ID = 1946a6504e90f80cb3bd21fb90b0be85&安培;页= 1&安培; league_id = 51&安培; lastsynced = 1340362314&安培;任务= match.schedule_syncable

  

没有重定向,但为什么它会激活willSendRequest?可以查看我的API的详细信息

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

2012-06-26 00:28:21.913 zozo [11726:18d03] * [90字节]网址: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] * [已完成]网址:http:// pm [dot] mvdigital [dot] vn / sandbox / zozo / smartphone.php lastsynced = 1340362261&安培;任务= 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字节]网址:http:// pm [dot] mvdigital [点] VN /沙箱/ ZOZO / smartphone.php页大小= 10&安培; SESSION_ID = 1946a6504e90f80cb3bd21fb90b0be85&安培;页= 1&安培; league_id = 51&安培; lastsynced = 1340362314&安培;任务= match.schedule_syncable

2012-06-26 00:28:26.422 zozo [11726:18d03] * [已完成]网址:http:// pm [dot] mvdigital [dot] vn / sandbox / zozo / smartphone.php页大小= 10&安培; SESSION_ID = 1946a6504e90f80cb3bd21fb90b0be85&安培;页= 1&安培; league_id = 51&安培; lastsynced = 1340362314&安培;任务= match.schedule_syncable

2012-06-26 00:28:26.423 zozo [11726:15203] sync matches sucessful

  

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

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

P / S: 我已经使用sharedclient尝试了AFHTTPClient,但我没有幸运。 我的服务器很好,我的Android客户端没有任何问题 有人有同样的问题吗?并发requets计数是否有任何限制?

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

感谢。

编辑:

  

我自己找到答案,点击此处:http://github.com/AFNetworking/AFNetworking/issues/387

0 个答案:

没有答案