问题
Caveat: I know that private frameworks won't fly in the App Store.
I'm trying to use the BluetoothManager framework to let me 1) check if Bluetooth is enabled on a device, and 2) if not on, turn it on.
I can successfully load BluetoothManager per the instructions found here, but once I've done so, BluetoothManager just doesn't seem to do anything.
Calling enabled always returns NO, even when Bluetooth is enabled. Calling setEnabled never changes its state. Absolutely every other BluetoothManager call I've tried always returns NO, nil, zero-element arrays, etc. In short, the BluetoothManager that gets returned seems totally neutered. (I'm running off my 4.2.1 iPhone, not the simulator.)
I've seen posts from people who claim to have gotten this working, yet I haven't been able to get a response from them. Can anyone shed light on why this might not be working?
Thanks very much.
回答1:
It takes a second for the BluetoothManager to startup and attach to the BTServer. I just did a quick call to the shared instance - [BluetoothManager sharedInstance];
- to force it to init. Once it's finished init it will post a BluetoothAvailabilityChangedNotification. I'd just listen for that and try [[BluetoothManager sharedInstance] setEnabled:YES];
in the notification callback.
FYI, the object included in the NSNotification for BluetoothAvailabilityChangedNotification is a boolean, so you should be able to check that to make sure that Bluetooth is really available.
回答2:
That's because of IPC. BluetoothManager communicates via sendMsg et el. Use for example NSTimer to query BluetoothManager sharedInstance so your program has time to receive and process messages.
回答3:
There is a demo project on Github called BeeTee for demonstrating the private framework BluetoothManager.
来源:https://stackoverflow.com/questions/5071509/ios-cant-get-bluetoothmanager-to-work