Carl Mangold

Flash & iPhone coding & concepting
  • Home
  • Bright.app
  • Commentaar
  • iPhone
  • Nieuws
  • Obj-C tips
16 Sep 2009

Tip: Gegarandeerd verbinding

Op het Vodafone 3G netwerk krijg je vaak pas verbinding nadat je je app een keertje uit en terug aan hebt gezet. En dat is natuurlijk bijzonder vervelend.

Met een Auto Retry los je dit probleem doeltreffend op:

NSURLConnection Auto Retry
  1. - (void)verversGegevens
  2. {
  3. self.navigationItem.rightBarButtonItem = _reloadButtonItemWithActivity;
  4. [self.view addSubview:_propellortje];
  5. [_propellortje startAnimating];
  6. [self.tableView setAlpha:.5];
  7.  
  8. _retryCount = 0;
  9. [_connection cancel];
  10. self.request = [NSURLRequest requestWithURL:[NSURL URLWithString:_remotePath] cachePolicy:0 timeoutInterval:5];
  11. self.connection = [[NSURLConnection alloc] initWithRequest:_request delegate:self];
  12. }
  13.  
  14. #pragma mark --- NSURLConnection delegate methods ---
  15.  
  16. - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
  17. {
  18. if (_retryCount++ < 2)
  19. {
  20. [_connection cancel];
  21. self.request = [NSURLRequest requestWithURL:[NSURL URLWithString:_remotePath] cachePolicy:0 timeoutInterval:15];
  22. self.connection = [[NSURLConnection alloc] initWithRequest:_request delegate:self];
  23. NSLog(@"Connection error -> RETRY");
  24. }
  25. else
  26. {
  27. self.navigationItem.rightBarButtonItem = _reloadButtonItem;
  28. [_propellortje stopAnimating];
  29. [_propellortje removeFromSuperview];
  30. NSLog(@"Connection error %@", error);
  31.  
  32. //TODO: foutmelding naar gebruiker
  33. }
  34. }

Tags: iPhone, obj-c, tip

This entry was posted on woensdag, september 16th, 2009 at 12:23 by Carl Mangold and is filed under Obj-C tips, iPhone. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply

Klik hier om het antwoord te annuleren.

« Layar: wat moet je ermee?
Met Layar moet je niet zoeken »
  • RSS

    • Alle berichten
    • Alle reacties
  • Archieven

  • Kalender

    • september 2009
      M D W D V Z Z
      « Aug   Okt »
      123456
      78910111213
      14151617181920
      21222324252627
      28293031  
  • CategoriĆ«n

    • Bright.app (4)
    • Commentaar (43)
    • iPhone (22)
    • Nieuws (2)
    • Obj-C tips (4)