0

I am building a video streaming app that allows users to create playlists and has content that updates quite regularly. It has 4 main views, each with a list of videos, the content of which is loaded as xml when the view is loaded and cached for a period of time (not when the app is loaded)

So basically at any time on any view the app requires a valid internet connection.

I have set the 'Application uses wifi' to YES in the plist.

I have tested the reachability example code as seen in this excellent answer How to check for an active Internet connection on iOS or OSX? and added it to each of my views viewDidLoad methods.

My question is how often and where should I implement this? am I right in including it in each views viewDidLoad or should I create some other class that I can call on more often?

Many thanks

Community
  • 1
  • 1
craigk
  • 1,284
  • 2
  • 12
  • 25

1 Answers1

0

You do not need to check continually the connection. You must check just before initiating an operation that requires a working connection. So, you do not check in viewDidLoad, or in another class.

You are in charge of reporting to your users that the connection is not available if this is the case. Before starting an operation requiring the connection to the Internet, you do the check. If the connection is not available notify immediately the users.

It may happen that the connection is available when you do the check but becomes unavailable later, during the operation. You must be careful here to include in your code a check for this. When you lose the connection, again you need to notify the users.

Massimo Cafaro
  • 25,154
  • 14
  • 76
  • 92
  • thanks for the answer unforgiven. By continually I meant 'on every button press that requires connectivity (and on every viewDidLoad as each UITableView requires xml from a server). So is the best way to do this to use the Reachability classes provided by apple and if so is it best to check for both internet and host connectivity each time? Sorry about the list of questions in a comment, I am worried about making a connection check on every click / view load - then calling the data required for that click / view. – craigk Apr 21 '11 at 06:53