小编des*_*top的帖子

核心蓝牙:CBPeripheral每隔约10秒钟断开连接

我在iOS 8.3中看到一个奇怪的错误,我想知道是否有其他人看到了同样的事情.

我有一个iPad Air(在中央模式下)和一个iPhone 6(在外围模式下)非常接近.

  • CBCentralManager的初始化是使用串行后台队列和CBCentralManagerOptionRestoreIdentifierKey选项
  • 管理员使用该CBCentralManagerScanOptionAllowDuplicatesKey: true选项开始扫描外围设备
  • centralManager:didDiscoverPeripheral:我内部检查已发现的外围设备列表:
let connect: () -> () = {
  peripheral.delegate = self
  self.devices[peripheral.identifier.UUIDString] = peripheral
  self.manager.connectPeripheral(peripheral, options: nil)
}

if let device = devices[peripheral.identifier.UUIDString] {
  if device.peripheral.state == .Disconnected {
    connect()
  }
} else if peripheral.state == .Disconnected {
  connect()
}
Run Code Online (Sandbox Code Playgroud)
  • 连接后,我会发现服务和特征.

现在外围设备在大约10秒后断开连接,立即再次发现并再次连接.10秒后,此程序重复进行.

这是一个错误还是我在这里做错了什么?

我也尝试直接订阅外围设备的特性,但这似乎没有改变任何东西.

bluetooth ios core-bluetooth

6
推荐指数
1
解决办法
2692
查看次数

C内存重叠吗?

我正在尝试将32字节字符串的前16个字节复制到dest

unsigned char src[32] = "HELLO-HELLO-HELLO-HELLO-HELLO-12";
unsigned char dest[16];

memcpy(dest, src, 16); // COPY

printf("%s\n", src);
printf("%lu\n", strlen(src));

printf("%s\n", dest);
printf("%lu\n", strlen(dest));
Run Code Online (Sandbox Code Playgroud)

输出如下

HELLO-HELLO-HELLO-HELLO-HELLO-12
32
HELLO-HELLO-HELLHELLO-HELLO-HELLO-HELLO-HELLO-12
48
Run Code Online (Sandbox Code Playgroud)

我期待收到HELLO-HELLO-HELLdest唯一。的前16个字节dest实际上包含预期的结果。

为什么dest超出其实际承受能力?为什么长度为16+32=48?有没有办法只复制前16个字节的srcdest

c string cstring memcpy memmove

1
推荐指数
1
解决办法
1769
查看次数

标签 统计

bluetooth ×1

c ×1

core-bluetooth ×1

cstring ×1

ios ×1

memcpy ×1

memmove ×1

string ×1