当我的 iOS 应用程序打开时,它会显示一个本地蓝牙设备列表,然后您单击一个。如果蓝牙关闭,则会出现系统警报,要求您将其打开(带有一个按钮可以转到“设置”,另一个按钮可以单击“确定”);如果您打开设置,它不会再次扫描,您必须
如何注册一种在蓝牙打开时运行方法的通知?
我看到了一些关于“BluetoothAvailabilityChangedNotification”的东西,但是当蓝牙打开/关闭时似乎没有被调用。
这是我尝试过的代码:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(bluetoothAvailabilityChanged:)
name:@"BluetoothAvailabilityChangedNotification"
object:nil];
...
-(void) bluetoothAvailabilityChanged: (NSNotification*) notification {
NSLog(@"Bluetooth changed %@",notification.description);
}