Search code examples
objective-ciosasihttprequestuser-experiencereachability

Polling network to determine whether network is reachable?


I was trying to implement ASIHTTPRequest to download files from a server. I have an option were user can add downloads to a queue and ASINetworkQueue handles the file downloads one by one.

I am trying to implement a feature wherein, if the user loses their network connection, my ASINetworkQueue should poll for network reachability continuously. Once connectivity is available again, the application starts downloading files from where it left off.

I am not asking for code, But I would appreciate if someone can help me with a array of hints.


To make my application download the file from where it left off, I am using the ASIHTTPRequest method

[request setAllowResumeForFileDownloads:YES];


Solution

  • You can use the Reachability APIs that apple provides illustrated in their Reachability sample code. See link.

    It allows you to receive callback when reachability changes, you can also poll reachability when appropriate, such as on applicationDidBecomeActive when if the reachability has changed when you were in the background you wouldn't have been informed.