I am implementing the Homekit app by taking the HMCatalog sample app. Everything is good but in the adding accessory view we are using EAWiFiUnconfiguredAccessoryBrowser for detecting the External accessories. In this first time everything working fine but if I go back and come forth it is not displaying the External accessories . Incase if I remove the HMCatalog app from background and relaunch then it is working fine. Asper my understanding there is some cache in the app . But I didn't find any cache related code in the app. Thank you for the valuable time. Please help me.
Code is:
// We can't use the ExternalAccessory framework on the iPhone simulator.
#if !TARGET_IPHONE_SIMULATOR
self.externalAccessoryBrowser = [[EAWiFiUnconfiguredAccessoryBrowser alloc] initWithDelegate:self queue:dispatch_get_main_queue()];
#endif
[self startBrowsing];
#pragma mark - EAWiFiUnconfiguredAccessoryBrowserDelegate methods
- (void)accessoryBrowser:(EAWiFiUnconfiguredAccessoryBrowser *)browser didFindUnconfiguredAccessories:(NSSet *)accessories
{
[self reloadTable];
}
- (void)reloadTable
{
[self resetDisplayedAccessories];
dispatch_async(dispatch_get_main_queue(), ^{
[allDevicesTableView reloadData];
});
}
- (void)resetDisplayedAccessories
{
[self.displayedAccessories removeAllObjects];
[self.displayedAccessories addObjectsFromArray:[self allAccessories]];
}
- (NSArray *)allAccessories
{
NSMutableArray *allAccessories = [[NSMutableArray alloc] initWithCapacity:0];
NSArray *discoveredAccessories = self.accessoryBrowser.discoveredAccessories;
if (discoveredAccessories)
{
[allAccessories addObjectsFromArray:discoveredAccessories];
}
[allAccessories addObjectsFromArray:self.addedAccessories];
NSArray *externalAccessories = self.externalAccessoryBrowser.unconfiguredAccessories.allObjects;
if (externalAccessories)
{
// ExternalAcessory framework may still contain an accessory for a little while after it's been configured.
// If there is a HomeKit accessory with the same name as any external accessory, filter out the external accessory.
NSPredicate *existingHomeKitAccessoryPredicate = [NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return ![[allAccessories valueForKeyPath:@"@distinctUnionOfObjects.name"] containsObject:evaluatedObject];
}];
NSArray *filteredExternalAccessories = [externalAccessories filteredArrayUsingPredicate:existingHomeKitAccessoryPredicate];
[allAccessories addObjectsFromArray:filteredExternalAccessories];
}
NSSortDescriptor *nameDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES
selector:@selector(caseInsensitiveCompare:)];
return [allAccessories sortedArrayUsingDescriptors:@[nameDescriptor]];
}