测试测试 | ✗ |
Lang语言 | Obj-CObjective C |
许可证 | MIT |
Released最后发布 | 2017 年 9 月 |
由 Akira Matsuda 维护。
请使用 git flow 并向 develop
分支发送拉取请求。
要运行示例项目,克隆仓库,然后首先从 Example 目录中运行 pod install
。
发送此类请求只需两个步骤。
// Send asynchronous request
M2DAPIRequest *r = [M2DAPIRequest GETRequest:[NSURL URLWithString:@"URL"]];
[[r whenSucceeded:^(M2DAPIRequest *request, NSDictionary *httpHeaderFields, id parsedObject) {
//When result condition is true
}] whenFailed:^(M2DAPIRequest *request, NSDictionary *httpHeaderFields, id parsedObject, NSError *error) {
//When result condition is false
}];
有许多方法可以控制每个序列。例如,
M2DAPIGatekeeper *gatekeeper = [M2DAPIGatekeeper sharedInstance];
[gatekeeper parseBlock:^id(NSData *data, NSError *__autoreleasing *error) {
id result = nil;
if (*error == nil) {
result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:error];
}
return result;
}];
[gatekeeper resultConditionBlock:^BOOL(M2DAPIRequest *request, NSURLResponse *response, id parsedObject, NSError *__autoreleasing *error) {
return [(NSHTTPURLResponse *)response statusCode] == 200;
}];
[gatekeeper initializeBlock:^(M2DAPIRequest *request, NSDictionary *params) {
dispatch_async(dispatch_get_main_queue(), ^{
// Show hud when start request
});
}];
[gatekeeper finalizeBlock:^(M2DAPIRequest *request, NSDictionary *httpHeaderField, id parsedObject) {
dispatch_async(dispatch_get_main_queue(), ^{
// Dismiss hud when finish request
});
}];
等等更多。
在启动连接时,会生成一个唯一标识符。您可以使用该标识符来取消请求。
NSString *identifier = [gatekeeper sendRequest:...];
[gatekeeper cancelRequestWithIdentifier:identifier];
请参阅 M2DAPIGatekeeper.h 或 M2DAPIRequest.h。
Akira Matsuda,[email protected]
M2DAPIGatekeeper 根据 MIT 许可证提供。有关更多信息,请参阅 LICENSE 文件。