问题
I have NSXMLParser problem, and i tried iOS8 NSXMLParser crash this topic, but i really did not get the solution.
I am creating another NXSMLParser delegate and setting its delegate in another class.
Could you please tell me what to do exactly, step by step? I am so confused.
Here is my code;
These lines of codes are inside the STXMLParser
STXMLParser2 *stXMLParser2 = [[STXMLParser2 alloc]init];
stXMLParser2.xmlParser = [[NSXMLParser alloc] initWithData:responseLoader.xmlData];
[stXMLParser2.xmlParser setDelegate:self];
[stXMLParser2.xmlParser setShouldResolveExternalEntities:YES];
[stXMLParser2.xmlParser parse];
回答1:
You can try this code:
dispatch_queue_t reentrantAvoidanceQueue = dispatch_queue_create("reentrantAvoidanceQueue", DISPATCH_QUEUE_SERIAL);
dispatch_async(reentrantAvoidanceQueue, ^{
STXMLParser2 *stXMLParser2 = [[STXMLParser2 alloc]init];
stXMLParser2.xmlParser = [[NSXMLParser alloc] initWithData:responseLoader.xmlData];
[stXMLParser2.xmlParser setDelegate:self];
[stXMLParser2.xmlParser setShouldResolveExternalEntities:YES];
[stXMLParser2.xmlParser parse];
});
dispatch_sync(reentrantAvoidanceQueue, ^{ });
回答2:
I was getting the same error and it turned out that the problem was due to calling a UI update in the func parserDidEndDocument(parser: NSXMLParser) which does not run on the main thread. After forcing the UI update in that function to run on the main queue, the problem was resolved.
回答3:
I encountered the same problem recently but it turned out that I had an exception in one of my delegates (KVO problem) and once I fixed that the reentracy error went away. So it might be worth to look for something else if you don't have an obvious multithreading or multiinstance problem.
来源:https://stackoverflow.com/questions/25642070/nsxmlparser-on-ios8-nsxmlparser-does-not-support-reentrant-parsing