9

I am using EAWiFiUnconfiguredAccessoryBrowser to detect EAWiFiUnconfiguredAccessory. The code to start the accessory search it's the following:

- (void)viewDidLoad {
    [super viewDidLoad];

    if (_accessories == nil) {
        _accessories = [[NSMutableArray alloc] init];
    }

    if (_browser == nil) {
        _browser = [[EAWiFiUnconfiguredAccessoryBrowser alloc] initWithDelegate:self queue:nil];
        _browser.delegate = self;
    }
}

Unfortunately it does find accessories only the first time the View loads. If I go back to the previous view and then reload the view it does not find them.

I tried:

  • recreating the browser accessory and restarting the search (does not work)
  • stopping the search and restarting it (does not work)

This is the latest code I got (refer to this together with the code above):

- (void) viewWillAppear:(BOOL)animated{
    NSLog(@"view will appear");

    if (_accessories != nil) {
        [_accessories removeAllObjects];
    }

    [self.tableView reloadData];
    [self initializeBrowswerAndStartSearch];
}

- (void) initializeBrowswerAndStartSearch{
    if (_browser != nil) {
        [_browser stopSearchingForUnconfiguredAccessories];
    }

    [_browser startSearchingForUnconfiguredAccessoriesMatchingPredicate:nil];
}

- (void) viewWillDisappear:(BOOL)animated{
    [_browser stopSearchingForUnconfiguredAccessories];
}

It seems that the accessory list information is cached somewhere within the APP. If I restart the APP it will find them so I guess there is something that I am missing.

Any help?

mm24
  • 9,280
  • 12
  • 75
  • 170
  • Yep.. I ended up leaving this part of the project for some weeks and focus on something else hoping that someone got an answer. Please keep me updated if you manage to find out why.. – mm24 Aug 20 '15 at 13:06
  • Official Apple example has the same problem. https://developer.apple.com/library/ios/samplecode/HomeKitCatalog/Introduction/Intro.html#//apple_ref/doc/uid/TP40015048 – Adinp Aug 20 '15 at 13:15
  • Eh eh... Apple.. they got billions and yet this happens, I hope they solve it soon. – mm24 Aug 20 '15 at 13:18
  • Try reloading the data a few seconds after the view is loaded. I've found that sometimes the list will be updated, but you won't get a notification about it. – msgambel Jun 12 '16 at 20:03

3 Answers3

5

so i have the same problem..you should use the unconfiguredAccessories array. Also, try keeping the instance of the browser alive. If you discover the device once, and you re-instantiate the browser, you wont find it again

Tushar Koul
  • 2,830
  • 3
  • 31
  • 62
2

EAWiFiUnconfiguredAccessoryBrowser has issues,and doesn't provide reliable result in certain use cases. i think you should try this

 - (void) viewWillAppear:(BOOL)animated{
       NSLog(@"view will appear");
       if (_accessories != nil) {
          [_accessories removeAllObjects];
       }

       [self.tableView reloadData];
       [self initializeBrowswerAndStartSearch];
  }

below method makes browser object nil and reinitialises it, in this case browser object will always return you updated(i.e, proper) values . it worked perfectly for me.

 -(void) initializeBrowswerAndStartSearch    
 {
       // Make EAWiFiUnconfiguredAccessoryBrowser  object nil and reinitiate ,start searching again 
       _browser = nil;
      _browser = [[EAWiFiUnconfiguredAccessoryBrowser alloc]      initWithDelegate:self queue:nil];
      [_browser startSearchingForUnconfiguredAccessoriesMatchingPredicate:nil];
 }

anytime you feel EAWiFiUnconfiguredAccessoryBrowser isn't providing proper result , try this.

n devaraj
  • 134
  • 9
1

I also have this issue. So I build a singleton called WAC service, then you can keep this singleton alive during the app life cycle. Anywhere you want to load the unconfigured accissories. Just load it from [_browser unconfiguredAccessories].

Damon
  • 11
  • 1