Swift 3: Can't connect to peripheral via BLE

隐身守侯 提交于 2019-12-05 06:15:01
func centralManager(central: CBCentralManager, didConnect peripheral: CBPeripheral) {}
--------------------^

Versus:

func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral)
--------------------^

The signature of the method is not the correct one, you are missing the _.

Method signatures are important. We can assume, since theses delegate methods are optional, that internally, the Apple code asks itself: Does my delegate have the method func centralManager(_ central: CBCentralManager, didConnect peripheral: CBPeripheral) implemented (respondsToSelector:)? In your case, not, because it's not the same, and then yours is not called.

You copy/paste the one from the doc or remove it and let XCode do its autocompletion thing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!