I have an application that has many views (Using tab bar controller). I want to make concurrent asynchronous http requests, independently of the current view that the user is viewing. When an http request is responded , I want to update the User Interface, and then request again. If I write the code inside a UIViewController Subclass, everything works fine. Where can I write my code so as to work , without knowing which tab the user is viewing? I would like to avoid using threads. Is that possible?
I have made a webservice that takes http requests and responds when it has something new. So, then i request for the new information and then i reopen the window for the webservice to talk me. That way I make a “persistent” connection.
Finally i would like to know, what is the best way to inform my model for the changes that will be made to it. NSNotification? Delegation?
UPDATE
The code below DOES NOT receive any response. It receives BAD_ACCESS and it crashes.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
// Request Data
ConnectionHandler *connectionHandler = [[ConnectionHandler alloc] init];
[connectionHandler requestSO];
[connectionHandler requestSopen];
// Make Root View Controller
MainViewController *mainViewcontroller = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
[self.window setRootViewController:mainViewcontroller];
//
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
It is wrong to avoid threads but if you want to run all the processes from a central place maybe the appDelegate is one place you could do it from. Personally I would be doing all of the network requests inside the model.