我在使用AFNetworking Get方法调用我的服务器时出现问题。 我在经理中使用此方法,类声明如下:
#import "AGZClient.h"
#import "AGZServiceModel.h"
// Constants used for every webservice call
static NSString * const agendizeApiKey = @"privateApiKey";
static NSString * const agendizeURLString = AGENDIZE_API_URL;
@implementation AGZClient
+ (AGZClient *)sharedAGZClient
{
static AGZClient *_sharedAGZClient = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
_sharedAGZClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:agendizeURLString]];
});
return _sharedAGZClient;
}
- (instancetype)initWithBaseURL:(NSURL *)url
{
self = [super initWithBaseURL:url];
if (self) {
self.responseSerializer = [AFJSONResponseSerializer serializer];
self.requestSerializer = [AFJSONRequestSerializer serializer];
//[self.requestSerializer setTimeoutInterval:100.0];
self.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json", nil];
}
return self;
}
// Get all the appointments for a company and a staff
- (void)getAppointmentsForCompany:(int)companyID andStaff:(int)staffID
{
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
parameters[@"apiKey"] = agendizeApiKey;
parameters[@"token"] = @"privateToken";
[self GET:[NSString stringWithFormat:@"companies/%d/appointments?staffId=%d", companyID, staffID] parameters:parameters success:^(NSURLSessionDataTask *task, id responseObject) {
if ([self.delegate respondsToSelector:@selector(AGZClient:successedReceiveAppointmentsForStaffList:)]) {
[self.delegate AGZClient:self successedReceiveAppointmentsForStaffList:responseObject];
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if ([self.delegate respondsToSelector:@selector(AGZClient:failedReceiveAppointmentsForStaffList:)]) {
[self.delegate AGZClient:self failedReceiveAppointmentsForStaffList:error];
}
}];
}
到达成功块但似乎当我的数据太大时,它不会等待数据,因此successBlock中的responseObject是nil
我不知道如何解决这个问题,为什么只有当所有数据都到达时才会调用成功块? 我该怎么做才能解决这个问题,请帮忙!