链式方法

liuyanwei edited this page Sep 29, 2015 · 2 revisions

谓词

在 baby.().().()链式函数体中,可以使用谓词方法and,then,with 让你的方法使用更加语义明确和优雅 例如:

  baby.having(self.p).and.channel(channelOnPeropheralView).
  then.connectToPeripherals().discoverServices().discoverCharacteristics()
  .readValueForCharacteristic().discoverDescriptorsForCharacteristic().readValueForDescriptors().begin();
  

链式方法的顺序

链式baby.().().() 方法按照CoreBluetooth蓝牙的顺序和限制。ios中蓝牙使用的顺序为:扫描->连接外设->发现服务->读取服务的characteristic->characteristic value、characteristic的descriptors和descriptor的value

  • begin()或者stop()为链式方法的结尾。若没有stop(),则begin()为结尾。
  • having(),channel()方法可以在任意begin()之前的位置。
  • 没有peripheral实例时,不能连接设备。在BabyBluetooth中就是不执行needScanForPeripherals(),那么执行connectToPeripheral()方法时必须用having(peripheral)传入peripheral实例。
  • 没有连接设备,不能执行discoverServices()
  • 没有执行discoverServices()不能执行discoverCharacteristics()、readValueForCharacteristic()、discoverDescriptorsForCharacteristic()、readValueForDescriptors()
  • 不执行discoverCharacteristics()时,不能执行readValueForCharacteristic()或者是discoverDescriptorsForCharacteristic()
  • 不执行discoverDescriptorsForCharacteristic()时,不能执行readValueForDescriptors()
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.