LoginSignup
0
0

More than 5 years have passed since last update.

RxBluetoothKitでの「状態の保存と復元」ハマりどころ

Posted at

本記事は下記バージョンで試した内容を書いてます。

iOS 10.3.1
Xcode 8.3.3
Polidea/RxBluetoothKit 3.1.1
ReactiveX/RxSwift 3.6.1

何がおきたのか

接続済みPeripheralからのNotifyトリガーで状態復元しても、Notifyが受け取れない。

原因を調べてみた

public func listenOnRestoredState() -> Observable<RestoredState>

で流れてきたRestoredState.peripheralsに対してサービスとキャラクタリスティックを探索&Notifyをsubscribeしていたが、そもそもサービス一覧が流れてこない。

対策

RestoredStateは使わずに、

public func retrieveConnectedPeripherals(withServices serviceUUIDs: [CBUUID]) -> Observable<[Peripheral]>

でPeripheral一覧取得してサービスとキャラクタリスティックを探索&Notifyをsubscribeでうまくいった。

おわりに

RxBluetoothKitでは状態の保存と復元できないのかと思って、危うく全部生のCoreBluetoothに書き換えるところだった・・・。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0