0
votes

I have this strange problem. am using NSXMLParser to parse my XML data that is fetched from the network. Even though the "parse" call returns success, the delegate functions are not being invoked when the iPhone app runs for the first time. But, the exact same XML is parsed just fine with the delegate callbacks called properly when I restart the process (iPhone4 running iOS4.2) by killing the background task & restarting the app. Exact same behavior in both simulator and phone.

NSXMLParser *lxmlParser = [[NSXMLParser alloc] initWithData:jData];
MyXMLParser *pxmlParser = [MyXMLParser initXMLParser];
[lxmlParser setDelegate:pxmlParser];

BOOL success = [lxmlParser parse];

Instead of killing the background task, if I just push the app to the background and bring it back to foreground, the problem stays. The only workaround is to KILL the running background task (yes, mine is a background task listening to "significant location change") and restarting the app. From now on, the parsing just works fine...

Can someone pls help ?

1

1 Answers

0
votes

What is the definition of [MyXMLParser initXMLParser]? If you're following the Cocoa memory management guideliness (and you should be!), it will return an object that is autoreleased (because it doesn't begin with 'alloc', 'new', 'copy'). So where does this object get retained permanently? If it's not retained, it may be getting dumped prematurely from memory when the current autorelease pool exits.

Btw, I'd choose a better method name for your autorelease construction method -- a method beginning with 'init' that isn't actually an init method is confusing. Renaming 'intXMLParser' to simply 'xmlParser' might be a good idea, stylistically.

Also, you've named an XMLParserDelegate implementation class as 'somethingXMLParser'. A better choice would be something like 'somethingXMLParserDelegate'.