1

I've recently finished an app which connects to a number of web services provided by my client. I've done this countless times in the past without any problems.

However, for some reason, with one of the services, which downloads about 250kb-1mb of data.

+ (void)connection:(MCURLConnection *)connection didReceiveData:(NSData *)data

Occasionally just stops after the first call.

Here's the log when it works

2014-08-19 11:57:43.270 MiniCheckout[886:60b] didReceiveResponse: didGetProductsForShop:
2014-08-19 11:57:43.270 MiniCheckout[886:60b] Code: 200
2014-08-19 11:57:43.271 MiniCheckout[886:60b] didReceiveData
2014-08-19 11:57:43.457 MiniCheckout[886:60b] didReceiveData
2014-08-19 11:57:43.645 MiniCheckout[886:60b] didReceiveData
2014-08-19 11:57:43.830 MiniCheckout[886:60b] didReceiveData
2014-08-19 11:57:44.003 MiniCheckout[886:60b] didReceiveData
2014-08-19 11:57:44.007 MiniCheckout[886:60b] didReceiveData
2014-08-19 11:57:44.169 MiniCheckout[886:60b] ConnectionFinished:didGetProductsForShop:

And when it doesn't (which is too often!)

2014-08-19 11:57:43.270 MiniCheckout[886:60b] didReceiveResponse: didGetProductsForShop:
2014-08-19 11:57:43.270 MiniCheckout[886:60b] Code: 200
2014-08-19 11:57:43.271 MiniCheckout[886:60b] didReceiveData

That's it, it just stops!

I have a timer which waits 60 seconds just so the app doesn't "lock up". But it occurs way too often and the client is not happy with this.

The web server/services are provided by the client and the issue occurs over Wifi and 3G.

I've handled web services countless times without problems. But I'm stumped as to why this is happening.

halfer
  • 19,824
  • 17
  • 99
  • 186
Dann
  • 323
  • 5
  • 17

1 Answers1

0

You can specify a timeout in your NSURLRequest object. One way to do this is to construct it via the requestWithURL:cachePolicy:timeoutInterval: method. (You can pass in the default NSURLRequestUseProtocolCachePolicy cachePolicy parameter if you don't want to worry about that part.) The timeout is a floating-point value in seconds, as are basically all time intervals in the iPhone SDK.

Also make sure your NSURLConnection's delegate is set and responds to the connection:didFailWithError: method. A connection always calls either this method or connectionDidFinishLoading: upon connection completion.

aBilal17
  • 2,974
  • 2
  • 17
  • 23