iphone - NSXMLParser initWithContentsOfURL timeout -


How can I set a timeout when I am parsing a feed using initWithContentsOfURL? Sometimes our feeds return an empty response and then it will only try to parse the feed forever. I want to integrate 30 seconds, so look at UAL-ul-view and then try to feed and re-insert.

  NSURL * feedURL = [[NSURL alloc] initWithString: URL]; NSXMLPers * Parser = [[NSX Parser Allok] Init with content of URL: feed URL]; [Parser set deliaget: self]; [Parser's sethold process namespace: no]; [Parser setshall reportnamePassprint: no]; [Parsets setSoldRSOLVXACATTTS: No]; [Parser pars];  

The first method: A delayed selector Perhaps the easiest way to do this is to use the method of NSBox. You can define some method parsingDidTimeout as such:

  - (zero) parsingditetimeout {if (self.parsingDidComplete == NO) {[self.parser abortParsing]; // Create your error and display it here // Try to reload and parse it again ...}}  

For this, you should assign a parser to an instance variable ( Self.parser ), so that you can cancel it with the method of defining it, it is also important that your parser representative takes care that parsing ( self.parsingDidComplete Whether it has been eliminated or not, it can be missed on NO and yes Representative's parserDidEndDocument: method). This is to avoid canceling a successful parse. After that, it is all simple.

  [Self display selector: @Selector (parsingead timeout) with object: After zero: 30 ];  

And after thirty seconds, your Parsing-Ebert code will be called, and you can do whatever you want to do.

Another way: Use the timer

You use the NSObject method instead of using this whole approach (logical) Can make it simple. In this way, if the parser is successfully finished, you can only invalidate the timer, from which you can get the if to parsingDidTimeout method (and, consequently, also ) Is allowed to eliminate BOOL ivar) timer initialization will look like this:

  NSTimer * timer = [NSTimer timerWill time: 30.0 target: auto selector : @sillector (parsingead timeout) userInfo: zero repeats: no]; [[NSRunLoop currentRunLoop] addTimer: Mode for Timer: NSDefaultRunLoopMode];  

Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -