A better Way to detect a broken pairing?
site_archiver@lists.apple.com Delivered-To: bluetooth-dev@lists.apple.com Hi there, So please, can anybode, give me a hint? Thanks a lot, Martin Häcker (well, today's not my day) _______________________________________________ Do not post admin requests to the list. They will be ignored. Bluetooth-dev mailing list (Bluetooth-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/bluetooth-dev/site_archiver%40lists.a... even after searching the Docs, the net and this list archive in particular, I didn't find a better way to detect a not anymore working bluetooth pairing than this: -- snip -- + (BOOL)deviceHasStalePairing:(BluetoothDeviceAddress) aDeviceAddress { IOBluetoothDevice* aDevice = [IOBluetoothDevice withAddress: &aDeviceAddress]; if ( ! aDevice) return NO; if ( ! [aDevice isPaired]) return NO; if (noErr != [aDevice openConnection]) return NO; if ( ! [aDevice isConnected]) { NSLog(@"[aDevice isConnected] returned false, but opening a connection worked fine, so we assume the pairing is broken / stale"); return YES; } // if the pairing is deleted on the mobile, this will sadly put up a password dialog on the mac // TODO: find an api which gives the same result, but doesn't put up this dialog IOReturn err = [aDevice requestAuthentication]; if (noErr != err) { NSLog(@"[aDevice requestAuthentication] returned: %d so we assume it's pairing is broken / stale", err); return YES; } return NO; } -- snap -- However, as you can see from the comment, this has the severe problem, that it a) catches a bit too much (some devices sometimes return error codes like 2, 6, 16, 19, 23, 26 and whatnot) of which we are not completely sure what they mean for the connection - especially if we get a 2 from requestAuthentication everything seems to still work. So I am searching for a different api, that gives me this information in a cleaner format, that is, that tells me straight out: can I communicate with this device, or do I need to create a new pairing? This API should also NOT try to reestablish the pairing on its own! (This last bit is quite important to me, as the GUI that provides is quite... not good). This email sent to site_archiver@lists.apple.com
participants (1)
-
Martin Häcker