Skip to content

Instantly share code, notes, and snippets.

@yuxiangq
Last active February 19, 2016 14:18
Show Gist options
  • Save yuxiangq/6bb4cf904a5e22b1187c to your computer and use it in GitHub Desktop.
Save yuxiangq/6bb4cf904a5e22b1187c to your computer and use it in GitHub Desktop.
递归 请求队列实现
//仅列出关键代码
@property (strong, nonatomic) NSArarry *datasArray;
- (void)beginUploadData {
[self uploadDataToServer:self.datasArray[0] index:0];
}
- (void)uploadDataToServer:(id)data index:(NSUInteger)index {
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager POST:@"url"
parameters:@{@"data":data}
success:^(AFHTTPRequestOperation *operation, id responseObject) {
if(index == self.datasArray.count - 1) {
//最后一条数据上传成功
}
else {
//上传下一条数据
[self uploadDataToServer:self.datasArray[index + 1] index:index + 1];
}
}
failure:^(AFHTTPRequestOperation *operation,NSError *error) {
//提示错误
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment