我可以在私有(private)框架的帮助下启用蓝牙。
现在我必须搜索附近的设备。 我想 deviceScanningEnabled 命令是正确的,但我如何获得返回的设备?有回调函数吗?我读到一些将在 NotificationCenter 中的通知?!
我该如何在这种情况下使用它?
最佳答案
据我所知,蓝牙管理器会在操作系统过滤结果后获取列表 - 这意味着您只会获取附近的耳机设备,而不是所有通用设备。如果您需要查找所有通用设备,则必须使用@rajagp 的答案。
如果找到耳机就足够了,那么你可以按照你说的使用通知;发现设备的通知称为“BluetoothDeviceDiscoveredNotification”。您首先需要列出通知:
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector( your_discovery_method_name)
name: @"BluetoothDeviceDiscoveredNotification"
object: nil];
“your_discovery_method_name”是您编写的显示/接受通知的方法。它看起来像这样:
-(void) your_discovery_method_name:(NSNotification *) notification {
self.device = [notification object];
NSLog(@"found: %@",self.device.address);
// ...
}
设备来自 BluetoothDevice 类型。
关于ios - 使用私有(private)框架 BluetoothManager/iOS 5.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8620953/