BLE Peripheral disconnects when navigating to different ViewController

前端 未结 1 1036
既然无缘
既然无缘 2020-11-29 09:40

I am working on BLE iOS (Swift) application which has multiple ViewControllers. The main ViewController has a button which navigates to TableViewController which has detecte

相关标签:
1条回答
  • 2020-11-29 10:37

    Create a Singleton class and add bleManager and peripheral properties there:

    class Shared { 
        private init(){ } 
        static let instance = Shared()
        var bleManager: BLEManager!
        var peripheral: CBPeripheral! 
    }
    

    And you can access the same instance through different controllers:

    Shared.instance.bleManager = BLEManager() 
    
    0 讨论(0)
提交回复
热议问题