5

デリゲートを取得したらdidConnectPeripheral:(CBPeripheral *)peripheral 、retrievePeripherals とそれに続くdidRetrievePeripherals. 実行可能でリスクがなければ、より簡単に思えます。

どのくらい(CBPeripheral *)peripheralで再利用できますか?その周辺機器との切断後も有効ですか?

ワークフロー:

  1. scanForPeripheralsWithServices()- 周辺機器をスキャンする
  2. didDiscoverPeripheral:(CBPeripheral *)peripheral- 検出されたとき connectPeripheral:peripheral
  3. didConnectPeripheral:(CBPeripheral *)peripheralstopScan を保存して(CBPeripheral *)peripheral、後で使用できるようにします。
  4. ... 読み取りまたは書き込みの特性 ...
  5. cancelPeripheralConnection
  6. didDisconnectPeripheral

後で再接続するには...

  1. connectPeripheral:peripheral- ペリフェラルを含むアレイから
  2. didConnectPeripheral:(CBPeripheral *)peripheral ...
4

1 に答える 1

5

YES, it will work (but it's terrible practice). The retrievePeripherals: method was specifically created so that you can reconnect to peripherals between subsequent launches of an application. You can use your method, but once the app is shutdown, you will never be able to connect to the peripheral again (without putting it into advertising mode and starting from scratch basically). You can store the uuid between launches, but you cannot store a CBPeripheral object. So there's the big downside right there.

So to sum up: it will work, but it doesn't really gain you anything. It is not faster than calling retrievePeripherals: and then connecting them. Your suggested method is only limiting your abilities for connections in CoreBluetooth. But an interesting question nonetheless.

于 2013-09-06T17:36:39.010 に答える