So the app I am writing has future potential for a range of accessories. I have no problem getting one accessory connected, but I want to obtain an array of all the accessories I support so I can prompt the user for which accessory they would like to use out of the ones connected. These accessories could be bluetooth or 30-pin.
I have this code, given to me by a manufacturer, that will scan for a device with their protocol string within an array they have created. The strange thing is that they loop through this array, but they only test if an item at index 0 matches their protocol string, unless I am reading it wrong of course. Could someone take a look at the code below and explain to me why they only search for an item at index 0? Is that perhaps reserved for the dock connector?
Quote:
-(NSArray *) devicesConnected
{
NSMutableArray *devices;
EAAccessoryManager *accessoryManager = [EAAccessoryManager sharedAccessoryManager]; [accessoryManager registerForLocalNotifications];
NSArray *array = [accessoryManager connectedAccessories]; EAAccessory *accessory;
for(accessory in array)
{
if ([[accessory.protocolStrings objectAtIndex:0] isEqualToString:@"com.*******.********"])
{
if (accessory.connected == true)
{
[devices addObject:[accessory.protocolStrings objectAtIndex:0]];
}
}
}
return devices;
}
|