这是一个可行的办法,虽然不是通过NSURLConnection的,但它不会阻止:
NSURL *xmlURL = [NSURL URLWithString:URL];
if (self.xmlParser != nil)
{
[self.xmlParser abortParsing];
self.xmlParser = nil;
}
dispatch_queue_t loadQueue1 = dispatch_queue_create("loadQueue1", NULL);
// Use another thread to avoid blocking main thread
dispatch_async(loadQueue1,^{
self.xmlParser = [[[NSXMLParser alloc] initWithContentsOfURL:xmlURL] autorelease];
// -------------------------------------------------------------------
[self.xmlParser setDelegate:self];
dispatch_async(dispatch_get_main_queue(),^{
if (self.xmlParser != nil)
{
[self.xmlParser parse];
}
});
});
dispatch_release(loadQueue1);
谢谢凯西,但这种方式,我想我无法验证证书认证。我想要异步调用但不冻结UI。 –