Note that there are some explanatory texts on larger screens.

plurals
  1. POReachability problem with notifications on a separate thread
    text
    copied!<p>I make use of Apples Reachability class and it works if I keep it on the main thread(bad approach). If I instead move it to a separate thread the notification is never called.</p> <p>In <code>didFinishLaunchingWithOptions</code> i call the following:</p> <pre><code>[NSThread detachNewThreadSelector:@selector(checkConnection) toTarget:self withObject: nil]; </code></pre> <p>checkConnection looks like follows:</p> <pre><code>-(void)checkConnection { //Test for Internet Connection NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachabilityChanged:) name:kReachabilityChangedNotification object:nil]; Reachability *r = [[Reachability reachabilityWithHostName:@"appspot.com"] retain]; [r updateReachability:appDelegate.reachability]; [r startNotifier]; [pool release]; } </code></pre> <p>and reachabilityChanged looks like this:</p> <pre><code>- (void)reachabilityChanged:(NSNotification *)note { Reachability* curReach = [note object]; NSParameterAssert([curReach isKindOfClass: [Reachability class]]); [self updateReachability: curReach]; } </code></pre> <p>and finally updateReachability looks like this:</p> <pre><code>- (void)updateReachability:(Reachability *)curReach { NetworkStatus internetStatus = [curReach currentReachabilityStatus]; if ((internetStatus != ReachableViaWiFi) &amp;&amp; (internetStatus != ReachableViaWWAN)) { NSLog(@"No net"); } else { NSLog(@"Lots of net"); }} </code></pre> <p>Hope you guys can help me to understand why <code>reachabilityChanged</code> is never called.</p> <p>Cheers...</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload