IOS: accessibility - startNotifier does not work after returning to the application

I have Reachability working exactly as suggested in this thread.

I use open source accessibility . However, I do not use blocks, but notifications, so this process is very similar to Apple Reachability code.

The first time I launch the application, I launch it and it works great.

Reachability *reachability = [reach hostReachability];
[reachability startNotifier];

Availability: changed event:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(reachability_Changed:) name:kReachabilityChangedNotification object:nil];

However, as soon as I press the home button and return to the application, it startNotifierreturns NO instead of YES.

    // Set it as our reachability queue, which will retain the queue
    if(!SCNetworkReachabilitySetDispatchQueue(self.reachabilityRef, self.reachabilitySerialQueue))
    {
#ifdef DEBUG
        NSLog(@"SCNetworkReachabilitySetDispatchQueue() failed: %s", SCErrorString(SCError()));
#endif
      ...
      return NO;

and therefore, the above event never fires again.

If I use it incorrectly, but startNotifiershould I call it only once in init, when the possibility of achievement is achieved and never again?

self.hostReachability = [Reachability reachabilityWithHostname:_HOST];
+4
1

[self.hostReachability startNotifier] /. , , - :

  • tonymillion/Reachability.

  • Reachability, , , .

    @interface ViewController () {
      NSString *_HOST;
    }
    @property Reachability *hostReachability;
    @end
    
  • , .

    - (void)viewDidLoad
    {
      [super viewDidLoad];
    
      [[NSNotificationCenter defaultCenter] addObserver:self
                                               selector:@selector(reachabilityChanged:)
                                                   name:kReachabilityChangedNotification
                                                 object:nil];
    
      _HOST = @"www.google.com";
      self.hostReachability = [Reachability reachabilityWithHostname:_HOST];
      [self.hostReachability startNotifier];
    }
    
    - (void)viewDidUnload
    {
      [super viewDidUnload];
    
      [[NSNotificationCenter defaultCenter] removeObserver:self];
    }
    
  • , reachabilityChanged: Reachability, .

    - (void)reachabilityChanged:(NSNotification*)notification
    {
      Reachability *notifier = [notification object];
      NSLog(@"%@", [notifier currentReachabilityString]);
    }
    

. "" , "" .

+2

All Articles