5

I have a situation here, I use rest API with AFNetworking to retrieve a specific resource (GET request) from our backend. When i check the backend with browser the result is 165 but in one specific device (one specific iPhone 6 plus) the result is 5, in any other device i retrieve 165 the correct answer. I think something cached the result on this device but doesn't found out anything on this specific device.

I deleted the application and installed it again and it works wrong again, so NSURLCache isn't the problem either

Code that i use to retrieve data from backend, it works fine any other devices, it doesn't work on that specific device. (by the way i use same username and password to check on all the devices and browsers) so this isn't the case.

AFHTTPRequestOperationManager* manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];

[manager.requestSerializer setValue:[[NSUserDefaults standardUserDefaults] valueForKey:TOKEN_ID_KEY] forHTTPHeaderField:TOKEN_HTTP_HEADER_NAME];
[manager GET:[NSString stringWithFormat:@"%@%@", BASE_URL, PROFILE_URL] parameters:nil success:^(AFHTTPRequestOperation* operation, id responseObject) {
    NSLog(@"profile info request accepted with response : %@",responseObject);
    profile = [[Profile alloc] initWithDictionary:responseObject];
    [self.tableView reloadData];
} failure:^(AFHTTPRequestOperation* operation, NSError* error) {
    NSLog(@"profile info request failed with eroor : %@" , [error localizedDescription]) ;
}];
Ali Riahipour
  • 524
  • 6
  • 20
  • can you post the piece of code where you send the request and handle the response? – Aviel Gross Jul 16 '15 at 06:22
  • About not caching the request - `AFNetworking` is using the shared `NSURLCache`, you can follow this answer to cancel caching for your app: http://stackoverflow.com/a/17063060/2242359 – Aviel Gross Jul 16 '15 at 06:30
  • @AvielGross I added code, i don't think it is something in my code wrong, because it is working on any other devices and on browsers, it doesn't work only on this specific device – Ali Riahipour Jul 16 '15 at 06:30
  • @AvielGross I deleted the application and installed it again and it works wrong again, so this isn't the problem either – Ali Riahipour Jul 16 '15 at 06:32
  • Try to use `Charles Proxy` from your iPhone on the bad device and on another device and see if the request is somehow different: http://www.charlesproxy.com/documentation/faqs/using-charles-from-an-iphone/ – Aviel Gross Jul 16 '15 at 06:33
  • @AvielGross I used that and they are exactly the same on two devices – Ali Riahipour Jul 16 '15 at 07:04
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/83396/discussion-between-aviel-gross-and-ali-rp). – Aviel Gross Jul 16 '15 at 07:05

2 Answers2

3

If you find out nothing to solve your problem then you can add current time at the end of the url. It happened to me as well and I just added something extra to my url so that it's always a new request.

long currentTime = (long)CFAbsoluteTimeGetCurrent();
NSString *urlString = [NSString stringWithFormat:@"%@%@?%ld", 
                                                BASE_URL, 
                                                PROFILE_URL, 
                                                currentTime];

This is just a workaround. Hope this helps

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184
1

The most simple approach would be to just disable the global NSURLCache, although I recommend against it.

NSURLCache *sharedCache = [[NSURLCache alloc] initWithMemoryCapacity:0
                                                        diskCapacity:0
                                                            diskPath:nil];
[NSURLCache setSharedURLCache:sharedCache];
  • first i can't disable cache, because we use map on this app so the tiles won't cached if i disable it, second i deleted the app and installed it again and the request isn't working again. so this won't help me – Ali Riahipour Jul 16 '15 at 06:37