我想知道如何获得仅返回值1或0 ....异步URL请求。如何发送异步URL请求?
目前我做了这种方式:
NSString *UTCString = [NSString stringWithFormat:@"http://web.blah.net/question/CheckQuestions?utc=%0.f",[lastUTCDate timeIntervalSince1970]];
NSLog(@"UTC String %@",UTCString);
NSURL *updateDataURL = [NSURL URLWithString:UTCString];
NSString *checkValue = [NSString stringWithContentsOfURL:updateDataURL encoding:NSASCIIStringEncoding error:Nil];
NSLog(@"check Value %@",checkValue);
这个作品,但它是挡住了我的主线程,直到我得到的答复从URL回来了,我该如何设置它,所以它会做它另一个线程而不是主线程?
编辑:ANSWER 我结束我的upcalling功能与此,它工作得很好:)
[self performSelectorInBackground:@selector(shouldCheckForUpdate) withObject:nil];
作为iOS 5的,则可以使用'+(无效)sendAsynchronousRequest:(的NSURLRequest *)请求队列:(NSOperationQueue *)队列completionHandler:(无效(^)(NSURLResponse *,NSData的*,NSError *) )handler`,这比创建一个委托对象更简单,更简单。我会尽量写出一个答案,稍后再显示这种方法。 – 2013-07-31 15:30:35
@MarkAmery很高兴看到您的答案。我很难找到一个简单的例子`sendAsynchronousRequest`。 – 2014-06-22 23:44:54