Last active
February 19, 2016 14:18
-
-
Save yuxiangq/6bb4cf904a5e22b1187c to your computer and use it in GitHub Desktop.
递归 请求队列实现
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//仅列出关键代码 | |
@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