How to reliably detect if an external keyboard is connected on iOS 9?

前端 未结 9 728
隐瞒了意图╮
隐瞒了意图╮ 2020-12-02 13:05

Previous to iOS 9, the most reliable method of determining whether an external keyboard is connected was to listen for UIKeyboardWillShowNotification and make a

9条回答
  •  不知归路
    2020-12-02 14:08

    You could try checking for peripherals that are advertising services using Core Bluetooth

    CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; 
    [centralManager scanForPeripheralsWithServices:nil options:nil];
    

    And you should implement the delegate:

    - (void)centralManager:(CBCentralManager * _Nonnull)central
     didDiscoverPeripheral:(CBPeripheral * _Nonnull)peripheral
         advertisementData:(NSDictionary * _Nonnull)advertisementData
                      RSSI:(NSNumber * _Nonnull)RSSI{
    
    }
    

提交回复
热议问题