Sending empty or no value in JSON webservice retrive faliure

I have 2 webservices, from which retrieve all images and other fetched filtered images from the webservice.
When the app loads it, call the web service that fetches all the images. And when the user applies filters, it retrieves the filtered images. But the problem I ran into:

Problem:
When the user selects at least one filter, it worked fine. But when the user does not select (means that no filters are selected), it jumps to an error. My webservice is coded in such a way that if there are no parameters, it should return all images, but it doesn't. I want it to download all image web links again.

With code Explanation:

[operation GET:@"stock_search" parameters:parameters success:^(AFHTTPRequestOperation *operation, id responseObject)
     {
       //  operation is AFHTTPRequestOperationManager
         NSMutableArray *temGalArray = [responseObject objectForKey:@"data"];
         [imageArray removeAllObjects];
         for (NSDictionary *myDict in temGalArray)
         {      
             id object = [myDict objectForKey:@"square_image"];

             if ([myDict objectForKey:@"square_image"]!=[NSNull null])
             {
                 [imageArray addObject:myDict]; //this works fine
             }
             else if([object isEqual:[NSNull null]])
             {
                 [self getGalleryFromWeb]; //***PROBLEM IS HERE***
                 //1: This condition is never true
                 //2: Self.getGalleryFromWeb is the webserivce that get 
                 //   all the images from web. There is no issue in that webservice
             }
         }
         [galleryView reloadData];
     }
           //It always loads failure code below
           failure:^(AFHTTPRequestOperation *operation, NSError *error)
     {
         UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error Applying Filters"
                                                             message:@"Check Your Internet Connection"
                                                            delegate:nil
                                                   cancelButtonTitle:@"OK"
                                                   otherButtonTitles:nil];
         [alertView show];
     }];
}

      

So what should I write in the `else if 'so that if no filter value is selected, it loads all the images again, just like when loading the application. Hopefully I have cleared my problem as this is my first question, so if there is anything I missed I am willing to provide.

+3


source to share


1 answer


When you get the selection at this time, check the number of filtered filters, and if it is> 0, then do not call the web service. This way your previously uploaded images will not be updated. Just try to filter the webservice only when the number of arrays is greater than> 0 and reload the data after that.



+2


source







All Articles