Question

I have an app with dynamic data and the update method uses arrayWithContentsofURL and dictionaryWithContentsofURL to get the plists from a server in order to update my database.

My problem:

When there is no or not correctly working internet connection on the device this request simply tries to get the data for about a minute before it stops trying and continues execution.

Is there a way to maybe set a timeout for this function?

PS: I know this is probably the worst way to do this and I would be happy if someone could point me in the right direction :) I'm quite new to iOS programming so please be patient.

Was it helpful?

Solution

In my opinion it's best to use an NSMutableURLRequest with it.

Which has a - (void)setTimeoutInterval method. From the documentation:

The timeout interval, in seconds. If during a connection attempt the request remains idle for longer than the timeout interval, the request is considered to have timed out. The default timeout interval is 60 seconds.

Suggest you use an NSURLRequest to send the Request object. Its delegate functions will return you the plist.

You could take this example, about half way on that page it downloads a json object very much the same way as you could fetch a plist.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top