我想获得有关BluetoothManager私有框架的所有通知。我一直在寻找,但我只发现了两个(BluetoothAvailabilityChangedNotification和BluetoothDeviceDiscoveredNotification)。 我很有兴趣在通知中报告iphone是否与设备连接/断开连接。如果有人能得到我所有通知的清单,我将不胜感激。
答案 0 :(得分:2)
我没有完整列表,但这些是你感兴趣的:
BluetoothDeviceConnectFailedNotification
BluetoothDeviceConnectSuccessNotification
BluetoothDeviceDisconnectFailedNotification // haven't confirmed this one
BluetoothDeviceDisconnectSuccessNotification
以下是其他一些内容:
BluetoothConnectabilityChangedNotification // fires when bluetooth is turned on/off
BluetoothAvailabilityChangedNotification // seems to fire once at app start)
BluetoothPowerChangedNotification
BluetoothDeviceDiscoveredNotification
BluetoothDeviceRemovedNotification
BluetoothPairingUserNumericComparisionNotification
BluetoothPairingPINResultSuccessNotification
答案 1 :(得分:1)
在致电[BluetoothManager sharedInstance]
之前添加:
CFNotificationCenterAddObserver(CFNotificationCenterGetLocalCenter(),
NULL,
bluetoothCallback,
NULL,
NULL,
CFNotificationSuspensionBehaviorDeliverImmediately);
在此实现中的某个地方,void bluetoothCallback:
void bluetoothCallback (CFNotificationCenterRef center,
void *observer,
CFStringRef name,
const void *object,
CFDictionaryRef userInfo)
{
if (CFStringGetCharacterAtIndex(name, 0) == 'B') { // stupid way to filter for only 'B'luetooth notifications
NSLog(@"%@", name);
}
}
您的控制台日志会立即显示所有蓝牙通知。