问题描述
的警告:我知道,私人框架不会在App Store飞的
我试图用BluetoothManager框架,让我1)检查是否蓝牙在设备上启用,并且2)如果不是,打开它。
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.
我可以成功加载BluetoothManager按照指令中找到here,但一旦我这样做,BluetoothManager只是似乎没有做任何事情。
I can successfully load BluetoothManager per the instructions found here, but once I've done so, BluetoothManager just doesn't seem to do anything.
电话启用总是返回NO,即使启用了蓝牙功能。调用的setEnabled不会改变其状态。绝对每隔BluetoothManager电话我已经试过总是返回NO,零,零元素的数组,等等,总之,这得到返回似乎完全阉割的BluetoothManager。 (我运行了我的4.2.1的iPhone,而不是模拟器。)
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?
非常感谢。
推荐答案
这需要一秒钟的BluetoothManager启动和附加到BTServer。我只是做了一个快速调用共享实例 - [BluetoothManager sharedInstance];
- 迫使它初始化。一旦它的完成初始化它会发布的 BluetoothAvailabilityChangedNotification 。我只是侦听,并尝试 [BluetoothManager sharedInstance]的setEnabled:YES];
的通知回调
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.
仅供参考,包含在NSNotification为对象的 BluetoothAvailabilityChangedNotification 是一个布尔值,所以你应该能够检查,以确保蓝牙是真的可用。
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.
这篇关于iOS版:无法获取BluetoothManager工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!