找出用户要求绑定 BLe 设备的决定 (Objective-C, iOS 10)
Find out users decision of asking to bond a BLe device (Objective-C, iOS 10)
是否可以让 iOS 的绑定请求的用户决定?
- 选择 1:放弃
- 选择 2:Connect/Bond
绑定请求截图:
我尝试使用 centralManagerDidUpdateState,但如果我打开蓝牙,它只会用 CBManagerStatePoweredOn 调用一次。
#pragma mark - CBCentralManagerDelegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
info(@"centralManagerDidUpdateState");
switch(central.state){
case CBManagerStateUnauthorized:
info(@"unauthorized");
break;
case CBManagerStatePoweredOff:
info(@"poweredOff");
break;
case CBManagerStatePoweredOn:
info(@"poweredOn");
break;
case CBManagerStateResetting:
info(@"resetting");
break;
case CBManagerStateUnknown:
info(@"unknown");
break;
case CBManagerStateUnsupported:
info(@"unsupported");
break;
}
}
我也试过用"didConnectPeripheral"和"didFailToConnectPeripheral":
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
[peripheral setDelegate:self];
[self _cancelConnectionRequests];
[peripheral discoverServices:nil];
BleDevice* bleDevice = [knownDevices findDevice:[peripheral.identifier UUIDString]];
devicePaired(bleDevice.deviceId, bleDevice.primaryServiceUuid);
}
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
[peripheral setDelegate:self];
[self _cancelConnectionRequests];
[peripheral discoverServices:nil];
BleDevice* bleDevice = [knownDevices findDevice:[peripheral.identifier UUIDString]];
deviceNotPaired(bleDevice.deviceId, bleDevice.primaryServiceUuid);
}
但是点击"Abort"或"Connect/Bond"后两种方法都没有被调用!
在尝试连接到设备时至少只调用 "didConnectPeripheral" - 但这是在弹出窗口出现之前发生的!
还有其他想法吗?
Note: I have no problems with scanning, connecting or bonding with a
BLe device - I only want to know if the user accepted the
bonding-request from his iPhone!
不,这不可能。我不知道苹果为什么做出这个决定,因为从安全的角度来看,应用程序知道 link 是否已正确加密和验证可能很重要。
如果你可以控制外围设备的固件,你可以让它在配对事件发生时发送一些特性。
是否可以让 iOS 的绑定请求的用户决定?
- 选择 1:放弃
- 选择 2:Connect/Bond
绑定请求截图:
我尝试使用 centralManagerDidUpdateState,但如果我打开蓝牙,它只会用 CBManagerStatePoweredOn 调用一次。
#pragma mark - CBCentralManagerDelegate
- (void)centralManagerDidUpdateState:(CBCentralManager *)central {
info(@"centralManagerDidUpdateState");
switch(central.state){
case CBManagerStateUnauthorized:
info(@"unauthorized");
break;
case CBManagerStatePoweredOff:
info(@"poweredOff");
break;
case CBManagerStatePoweredOn:
info(@"poweredOn");
break;
case CBManagerStateResetting:
info(@"resetting");
break;
case CBManagerStateUnknown:
info(@"unknown");
break;
case CBManagerStateUnsupported:
info(@"unsupported");
break;
}
}
我也试过用"didConnectPeripheral"和"didFailToConnectPeripheral":
- (void)centralManager:(CBCentralManager *)central didConnectPeripheral:(CBPeripheral *)peripheral {
[peripheral setDelegate:self];
[self _cancelConnectionRequests];
[peripheral discoverServices:nil];
BleDevice* bleDevice = [knownDevices findDevice:[peripheral.identifier UUIDString]];
devicePaired(bleDevice.deviceId, bleDevice.primaryServiceUuid);
}
- (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(NSError *)error {
[peripheral setDelegate:self];
[self _cancelConnectionRequests];
[peripheral discoverServices:nil];
BleDevice* bleDevice = [knownDevices findDevice:[peripheral.identifier UUIDString]];
deviceNotPaired(bleDevice.deviceId, bleDevice.primaryServiceUuid);
}
但是点击"Abort"或"Connect/Bond"后两种方法都没有被调用! 在尝试连接到设备时至少只调用 "didConnectPeripheral" - 但这是在弹出窗口出现之前发生的!
还有其他想法吗?
Note: I have no problems with scanning, connecting or bonding with a BLe device - I only want to know if the user accepted the bonding-request from his iPhone!
不,这不可能。我不知道苹果为什么做出这个决定,因为从安全的角度来看,应用程序知道 link 是否已正确加密和验证可能很重要。
如果你可以控制外围设备的固件,你可以让它在配对事件发生时发送一些特性。