gpt4 book ai didi

iOS 蓝牙 : central- peripheral got connected before accepting pairing request

转载 作者:行者123 更新时间:2023-11-28 21:34:39 25 4
gpt4 key购买 nike

我在使用一台设备与其他设备通信时遇到了一些蓝牙连接问题,这些设备遵循 CBCentral 和 CBPeripherel 概念。但是,外围设备在接受配对请求弹出之前连接到中央,基本上中央在接受配对请求之前将一些数据传递给外围设备。

-- (void)peripheral:(CBPeripheral *)peripheral didDiscoverCharacteristicsForService:(CBService *)service error:(NSError *)error

{

for (CBCharacteristic *characteristic in service.characteristics)
{

NSLog(@"for loop for charactersitc %@",characteristic.UUID);
// And check if it's the right one
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_SLIDEINDEX_CHARACTERISTIC_UUID]])
{
// If it is, subscribe to it
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_SCROLL_CHARACTERISTIC_UUID]])
{
// If it is, subscribe to it
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}

if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:TRANSFER_FULLSCREEN_CHARACTERISTIC_UUID]])
{
// If it is, subscribe to it
[peripheral setNotifyValue:YES forCharacteristic:characteristic];
}
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:SLIDELENGTH_CHARACTERISTIC_UUID]])
{
// WRITE VALUES TO REMOTE
NSInteger length = self.presentationDataSourceArray.count;
NSData *chunk = [NSData dataWithBytes: &length length: sizeof(length)];

[self.discoveredPeripheral writeValue:chunk forCharacteristic:characteristic
type:CBCharacteristicWriteWithResponse];
[self.discoveredPeripheral setNotifyValue:YES forCharacteristic:characteristic];

}
if ([characteristic.UUID isEqual:[CBUUID UUIDWithString:DEVICENAME_CHARACTERISTIC_UUID]])
{
NSString *deviceName = [[UIDevice currentDevice]name];
NSData *chunk = [deviceName dataUsingEncoding:NSUTF8StringEncoding];
[self.discoveredPeripheral writeValue:chunk forCharacteristic:characteristic
type:CBCharacteristicWriteWithResponse];
[self.discoveredPeripheral setNotifyValue:YES forCharacteristic:characteristic];

NSLog(@"Sending Device Name");
}
if ([characteristic.UUID isEqual: [CBUUID UUIDWithString:CURRENTSLIDE_CHARACTERISTIC_UUID]])
{
self.currentSlideIndexCharacterestics = (CBMutableCharacteristic*) characteristic;
NSInteger count = self.currentPage;
NSData *chunk = [NSData dataWithBytes: &count length: sizeof(count)];

[self.discoveredPeripheral writeValue:chunk forCharacteristic:characteristic
type:CBCharacteristicWriteWithResponse];
[self.discoveredPeripheral setNotifyValue:YES forCharacteristic:characteristic];
}


_isRemoteConnected = YES;
}

最佳答案

问题不在您的应用程序中,而是在您的 BLE 设备中。
BLE设备的数据无需配对即可写入和读取。完全可以。
仅当您尝试访问加密字符的数据时才会启动配对请求,该数据在外围端配置如下:

emailCharacteristic = [[CBMutableCharacteristic alloc]
initWithType:emailCharacteristicUUID
properties:CBCharacteristicPropertyRead
| CBCharacteristicPropertyNotifyEncryptionRequired
value:nil permissions:CBAttributePermissionsReadEncryptionRequired];

所以在你的情况下,你的一些外围设备的角色需要配对,而其他的则不需要。

你可以在CorebluetoothGuide中看到更多

关于iOS 蓝牙 : central- peripheral got connected before accepting pairing request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34358639/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com