1

one of my iOS Apps uses NSURLSession to connect to a web service and query some data. I have just added and released this feature and in most cases it seems to work without any problems. However a hand full of customer report, that they are not able to uses the feature when the devices is connected to the internet using a mobile network. Using the feature on a WiFi connection is no problem on the other hand.

The code is nothing special but just a simple NSURLReqeust using NSURLSession

NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig delegate:self delegateQueue:[NSOperationQueue mainQueue]];

NSMutableURLRequest* request = [[NSMutableURLRequest alloc] initWithURL:myServiceURL];
[request addValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setHTTPMethod:@"GET"];

[[session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
    if (error != nil) {
        // Log error...
    } else {
        // Handle response...
    }
}] resume];

When the users run the feature on a mobile connection the request failes with error code -1009 which is kCFURLErrorNotConnectedToInternet. OK, so no internet connect. But the users report, that all other services/apps like E-Mail, Safari, WhatsApp, etc. work without any problem on the same connection.

Any idea what might be going on here? Right now I have no idea in what direction to search for the problem. In my tests everything works just fine, no matter what kind of connection is used. Many other users report, that the also have no problem using the feature on mobile connections.

Andrei Herford
  • 17,570
  • 19
  • 91
  • 225
  • Could you show the code for `createCheckRequest` method? Also don't you check for [Reachability](https://developer.apple.com/library/ios/samplecode/Reachability/Introduction/Intro.html), before creating a request? – Vin Mar 18 '16 at 09:00
  • No, I do not check for Reachability but I will add this in a future version. Right now the code simply fires the request and waits for its response. I removed the `createCheckRequest` call from the code in the question since it was only a copy error. The real request is already shown: I simple call to an URL with Accept header and HTTPMethod set. Also: If the configuration of the request is incorrect, it should fail no matter what connection is used, shouldn't it? – Andrei Herford Mar 18 '16 at 09:26
  • I've received complaints from clients on cellular networks exhibiting the same issue. Works fine on wi-fi, but for a handful of users - shows this error. – Moshe Gottlieb Apr 14 '16 at 05:37
  • @iMoses Sorry, I should have posted my solution for that problem earlier. I have no added the answer below. Maybe this can help you as well... – Andrei Herford Apr 14 '16 at 09:42
  • @AndreiHerford Thanks, will try to find out if that was the issue (I can't think of anything else...) – Moshe Gottlieb Apr 14 '16 at 09:44

1 Answers1

0

for all how might experience the same problem: The solution is quite simple.

For some reason (the user has no idea why) mobile data usage was deactivated for my app. This can be done in the iOS system settings under Settings/Mobil Data/Use Mobile Data for:

I also have no idea how this can happen. Before working on this error I even did not know, that one can disable mobile data usage on per app basis. Maybe this happened by accident or by some bug of the system? However, after the user re-enabled the mobile data usage, my app work as expected again.

Andrei Herford
  • 17,570
  • 19
  • 91
  • 225