I have an application that can be started from the web via a URI scheme, that I have registered in my app. Depending on the URI, I open different view controllers (by setting the rootViewController in AppDelegate). Each view controller asynchronously gets some initialization data from a server upon initialization.
My problem is: If my server responds slowly and I go out of the application and enter the application again (causing a new view controller to open), then the first view controller still exists in the background and receive the server response for the request that it sent. This can cause an alert to be shown by the first view controller, even though that view controller is no longer in focus.
I could fix this by setting a flag in the viewDidDisappear: method. But this kind of handling messes up the code, and it would be much nicer if I could somehow stop the view controller from the AppDelegate. Or at least ensure that it only displays an alert view if it is in the foreground. Is there any way to do one of these things?
I found a possible solution in another SO question
This avoids the flags, but it still needs to be spread out where alert views are presented.