我有一个具有许多视图的应用程序(使用标签栏控制器)。我想创建并发的异步http请求,与用户正在查看的当前视图无关。当一个http请求被响应时,我想更新用户界面,然后再次请求。如果我在UIViewController子类中编写代码,一切正常。在哪里可以编写我的代码以便工作,而不必知道用户正在查看哪个标签?我想避免使用线程。那可能吗?背景中的多个异步HTTP请求iPhone
我做了一个web服务,它接受http请求并在它有新的东西时作出响应。所以,然后我要求提供新的信息,然后我重新打开Web服务的窗口与我交谈。这样我就可以建立一个“永久”连接。
最后,我想知道,什么是最好的方式告知我的模型将作出的变化。 NSNotification?代表团?
UPDATE
下面的代码不接收任何响应。它收到BAD_ACCESS并且崩溃。
- (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;
}
上看到Apple的示例XMLPerformance为什么要避免线程出错? – 2012-02-29 12:36:11
在单独的后台线程(在主线程之外)运行您的请求会使您的应用程序用户界面响应。如果你的UI由于在主线程中运行了所有进程而非常不响应,那么你的应用可能会被OS所杀,并且至少你的用户会对它进行评估/评估。请参阅http://www.raywenderlich.com/4295/multithreading-and-grand-central-dispatch-on-ios-for-beginners-tutorial – ader 2012-02-29 13:13:36