ios蓝牙开发错误总结

1.didConnectPeripheral不调用

原因:CBPeripheral对象居然会被释放掉,在这里对它用的是个weak?虽然我不太相信,但还是赶紧试了试答案了说的方法,写了个全局的属性对CBPeripheral强引用。果然,接下来一切OK,后面的内容写起来畅通无阻。

心里还是有点疑惑,就去找文档,然后找到这样一句话:

You must retain a local copy of the peripheral if any command is to be performed on it.

解决:

 @property (nonatomicstrongNSMutableArray *peripherals;//全局的


[self.peripherals addObject:peripheral];

[central connectPeripheral:peripheral options:nil];//执行这个peripheral必须强引用




猜你喜欢

转载自blog.csdn.net/haoxuhong/article/details/80252782