簡體   English   中英

iOS CoreBluetooth重新連接應用程序在后台

[英]iOS CoreBluetooth reconnecting while app in background

我的問題是“如果應用程序不在前台,我該如何重新連接到設備”? 我已經完成了我的研究,似乎連接到配對設備的最佳方式是通過retrivePeripherals:UUID。 一旦找到了回復的didRetivePeripherials,我就可以嘗試重新連接到設備。 當應用程序在后台運行時,我似乎無法做到這一點。

感謝幫助。

安德烈斯N.

  1. 啟用bluetooth-central后台模式
  2. 在實例化CBCentralManager時使用CBCentralManagerOptionRestoreIdentifierKey選項提供唯一標識符
  3. 實現- (void)centralManager:(CBCentralManager *)central willRestoreState:(NSDictionary *)state delegate方法
    3.1使用NSArray *peripherals = state[CBCentralManagerRestoredStatePeripheralsKey]獲取可恢復外設陣列NSArray *peripherals = state[CBCentralManagerRestoredStatePeripheralsKey]
    3.2調用connectPeripheral你的方法CBCentralManager提供每個外設恢復

閱讀“ 核心藍牙編程指南”中的更多詳細信息

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM