我正在使用AFNetworking 2.0从服务器获取数据。在我的AppDelegate中,我几乎同时发布了两个请求,并且响应1有时返回到request2并且request1超时。
这是我的http客户端类,有什么问题吗?请帮帮我,非常感谢你。
·H
#import <Foundation/Foundation.h>
#import <AFNetworking.h>
@interface HttpClient : AFHTTPRequestOperationManager
+ (instancetype)sharedHTTPClient;
- (instancetype)initWithBaseURL:(NSURL *)url;
- (NSDictionary *)getDataWithDictionary : (NSDictionary *) dic
success : (void (^)(NSDictionary* dictionary))success
failure : (void (^)(NSError *error))failure
networkError : (void (^)(BOOL isNetworkError))networkError;
@end
的.m
@implementation HttpClient
+ (instancetype)sharedHTTPClient{
static HttpClient *_sharedHTTPClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedHTTPClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:kReachability]];
});
return _sharedHTTPClient;
}
- (instancetype)initWithBaseURL:(NSURL *)url{
self = [super initWithBaseURL:url];
if (self) {
self.responseSerializer = [AFHTTPResponseSerializer serializer];
}
return self;
}
- (NSDictionary *)getDataWithDictionary : (NSDictionary *) dic
success : (void (^)(NSDictionary* dictionary))success
failure : (void (^)(NSError *error))failure
networkError : (void (^)(BOOL isNetworkError))networkError{
if ([CheckNetwork isExistenceNetwork]) {
[self POST:[NSString stringWithFormat:@"%@%@",kReachability,@"/interfaces/"]
parameters:parameters
success:^(AFHTTPRequestOperation *operation, id responseObject) {
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
}];
}else{
}
return nil;
}
@end