使用AFHttpRequestOperationManager进行GET请求不能使用3G

时间:2017-01-24 14:55:11

标签: ios objective-c httprequest

使用AFHttpRequestOperationManager的GET请求不在3G上工作仅适用于wifi

这是我的代码

它在wifi上或请求数据兑现时正常工作 我发现了一个针对POST请求的问题

-(void)getHomeworksWithChildId:(double)childId AndIsFromRecycleBin:(NSNumber*) isFromRecyclebin
{
    if (([isFromRecyclebin isEqualToNumber:@1])) {
        isFromRecyclebin = @0;
    }
    else
        isFromRecyclebin = @1;

    NSString *reportsUrl  = [self getFullURLString:[NSString stringWithFormat:homeworks_URL,self.currentUser.iDProperty,childId,isFromRecyclebin]];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFJSONResponseSerializer serializerWithReadingOptions:NSJSONReadingAllowFragments];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"];
    [manager GET:reportsUrl parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
         if ([(NSArray*)responseObject count]>0)
         {

             NSMutableArray *allPictures = [[NSMutableArray alloc]init];
             for (int i=0; i<[(NSArray*)responseObject count]; i++) {
                 Report *report = [[Report alloc]initWithDictionary:[responseObject objectAtIndex:i]];
                 [allPictures addObject:report];
             }
             NSDictionary *userInfo= [[NSDictionary alloc]initWithObjects:@[allPictures,@0] forKeys:@[@"reports",@"digital"]];
             NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
             [defaults setInteger:1 forKey:@"catname"];
             [defaults synchronize];
             [SVProgressHUD showSuccessWithStatus:NSLocalizedString(@"", @"")];
             [[NSNotificationCenter defaultCenter] postNotificationName:REPORTS_RECIEVED_NOTIFICATION object:nil userInfo:userInfo];
         }
         else
             [[NSNotificationCenter defaultCenter] postNotificationName:REPORTS_RECIEVED_NOTIFICATION object:nil userInfo:nil];
     } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
         [[NSNotificationCenter defaultCenter] postNotificationName:REPORTS_RECIEVED_NOTIFICATION object:nil userInfo:nil];
         [SVProgressHUD showErrorWithStatus:error.localizedDescription];
         NSLog(@"Error: %@", error);
     }];
}

0 个答案:

没有答案