I realize it is impossible to actually utilize any external accessories that are not MFI certified with the iPhone. Is there any way to simply detect a connection? All I would like to do is acquire the serial number from a USB drive.
So far I've tried the following
- (void)pollAccessories {
statusText.text = [NSString stringWithFormat:@"%@%@", statusText.text, @"\r\nPolling Accessories..."];
NSArray *accessories = [[EAAccessoryManager sharedAccessoryManager] connectedAccessories];
for (EAAccessory *obj in accessories){
statusText.text = [NSString stringWithFormat:@"%@%@", statusText.text, @"\r\nLocated Accessory"];
if(obj.connected)
statusText.text = [NSString stringWithFormat:@"%@%@", statusText.text, @"\r\nConnected\r\n"];
}
}
Seems to work in the simulator (I'm getting two accessories that are "connected"). Ran it on my phone connecting to a PC and my PS3 with no joy. Unfortunately I don't have the appropriate dongle on hand to test a proper usb drive.
UPDATE 4/27/11:
I managed to test my code on an iHome radio. It does detect the connection, so the code is working. I've ordered a USB dongle to see if I can detect a thumb drive.
I got my hands on a USB dongle and sadly the OS provides no indication of a connection to a non-MFI device. This is not possible without some sort of intermediary dongle that is MFI certified.
来源:https://stackoverflow.com/questions/5774906/is-it-possible-to-detect-non-mfi-accessories-on-the-iphone