大佬教程收集整理的这篇文章主要介绍了iphone – 长的投票在客观C,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
- (void) longPoll { //create an autorelease pool for the thread NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; //compose the request NSError* error = nil; NSURLResponse* response = nil; NSURL* requestUrl = [NSURL URLWithString:@"http://www.mysite.com/pollUrl"]; NSURLRequest* request = [NSURLRequest requestWithURL:requestUrl]; //send the request (will block until a response comes back) NSData* responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; //pass the response on to the handler (can also check for errors here,if you want) [self performSelectorOnMainThread:@selector(dataReceived:) withObject:responseData waitUntilDone:YES]; //clear the pool [pool drain]; //send the next poll request [self performSelectorInBackground:@selector(longPoll) withObject: nil]; } - (void) startPoll { //not covered in this example: stopping the poll or ensuring that only 1 poll is active at any given time [self performSelectorInBackground:@selector(longPoll) withObject: nil]; } - (void) dataReceived: (NSData*) theData { //process the response here }
或者,您可以使用异步I / O和委托回调来完成同样的事情,但在这种情况下,这真的会是一种愚蠢的事情.
以上是大佬教程为你收集整理的iphone – 长的投票在客观C全部内容,希望文章能够帮你解决iphone – 长的投票在客观C所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。