1

In my iOS project, I use NSURLConnection to download files. My code is just like the http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html document. In my team's Android project, we use Android's API to download the same files. Nothing special either. Both the iOS and Android project have the same fail-retry mechanism, and both of them send the same statistic data to server. The files they trying to download is between 1M to 10M.

The statistic server shows that for the same URL, download failure is 2% on android, but 20% on iOS! Since they are trying to download the same URL, it seems not the server's problem but more like a client issue.

Why iOS download would fail so frequently? Is there any special APIs I should use for iOS, to make the download robust? Currently I'm using NSURLConnection, and I've just found NSURLDownloader which is more convenient to write files. Will they be different for download success percentage?

P.S. the error I got by -
(void) connection: (NSURLConnection *) connection didFailWithError: (NSError *) , is usually -1005, NSURLErrorNetworkConnectionLost.

Miral Dhokiya
  • 1,720
  • 13
  • 26
ElfeXu
  • 317
  • 2
  • 15
  • 3
    couldn't be a problem in your code, could it? – Mitch Wheat Dec 24 '12 at 03:44
  • are you sure it's 20% actual failures, and not 20% users aborting? – Marc B Dec 24 '12 at 03:46
  • We've reviewed the code carefully several times, and I'm pretty sure there is nothing special. – ElfeXu Dec 24 '12 at 03:47
  • 2
    What about a memory leak or otherwise running out of memory? We have no info on how you're dealing with the download. – Remear Dec 24 '12 at 03:47
  • @ElfeXu: If the file is that big, I guess you should try writing it to file? – nhahtdh Dec 24 '12 at 03:49
  • Double checked and yes, it's failure. – ElfeXu Dec 24 '12 at 03:49
  • Reachability issues? I've tested in places where the WiFi and even cellular dropped out at odd times and caused anomalous connection failures. – Remear Dec 24 '12 at 03:49
  • If it's actually a failure, what's reported in the didFailWithError delegate callback? – Remear Dec 24 '12 at 03:50
  • @Remear The way I process data, is while got - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data, I write data to a tmp file. I guess NSURLDownloader will do the similar thing, correct? – ElfeXu Dec 24 '12 at 03:53
  • It should... https://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSURLDownload_Class/Reference/Reference.html It's been a while since i've used it. – Remear Dec 24 '12 at 03:54
  • 2
    Implicit in all of these questions, failure rates like this are unusual. Despite your assurances, the code is the likely culprit. You probably should share your download code. – Rob Dec 24 '12 at 03:57

1 Answers1

1

I'd suggest looking more into why you're getting NSURLErrorNetworkConnectionLost. Even if your device says it's connected, sometimes it could lose the connection and be attempting to regain it before the indicators update accordingly.

This is a good starting point for more information on better dealing with reachability. Checking For Internet Connectivity in Objective C

Otherwise, I recommend you post your download-related code so others can look for possible issues.

Community
  • 1
  • 1
Remear
  • 1,927
  • 12
  • 19