NRaf
NRaf

Reputation: 7549

Handling Internet drop-outs on the iPhone

I'm working on an iPhone that heavily interacts with a server. I'm at the stage now where I'm considering how to react to things like network failure and session timeouts.

The two most common tasks that will occur is response to network issues are: 1 - A message informing the user that the net cannot be reached and asking them to try again later (UIAlertView) 2 - Certain failures will cause the user to return to the login screen

I want to be able to handle these in a clean way. At the moment, there's the GUI and the Service layer. The Service layer has no knowledge of the GUI - it's the responsibility of the view to declare delegate methods that get called when the data is returned.

I don't, however, want to require the ViewController to have to handle the two tasks mentioned above. I will create delegate methods that get called on failure but these are mainly to handle any clean-up required for that ViewController (i.e. stopping the loading indicator).

As for the actual message handling and return to login screen, I'd prefer that be handled by a centralized class. I'm thinking of creating another class that controls the interface from the GUI layer to the Service layer. That way, when it detects a failure, it can respond correctly.

Any ideas how I should approach this? Can an NSObject display an NSAlertView or do I have to create a class that inherits from UIView? Does this strike you as a good way to approach the issue? Any recommendations from experience, etc?

Upvotes: 1

Views: 147

Answers (1)

Steven Veltema
Steven Veltema

Reputation: 2150

Why not use NSNotificationCenter to communicate between your service layer and the GUI, with the GUI controllers as observers for notifications from the service or network layer.

Take a look at http://www.mlsite.net/blog/?p=1618 for one example

Upvotes: 1

Related Questions