【问题标题】:BluetoothManager Framework Notifications ListBluetoothManager 框架通知列表
【发布时间】:2012-05-20 14:43:21
【问题描述】:

我想获取 BluetoothManager 私有框架的所有通知。我一直在搜索,但只找到了两个(BluetoothAvailabilityChangedNotification 和 BluetoothDeviceDiscoveredNotification)。 我对报告 iphone 是否连接/断开设备的通知很感兴趣。如果有人能给我一份所有通知的列表,我将不胜感激。

【问题讨论】:

  • 您手头是否有蓝牙设备会导致此类事件发出信号?如果是这样,为什么不自己检查一下-> stackoverflow.com/questions/3725234/…(请注意答案的最后更新)。
  • 谢谢。像魅力一样工作。
  • 非常好的资源,谢谢。

标签: iphone objective-c ios bluetooth iphone-privateapi


【解决方案1】:

我没有完整的列表,但这些是您感兴趣的:

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

【讨论】:

    【解决方案2】:

    打电话前加[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);
        }
    }
    

    您的控制台日志现在向您显示所有蓝牙通知。

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-14
    • 1970-01-01
    • 1970-01-01
    • 2011-08-20
    • 2018-10-05
    相关资源
    最近更新 更多