Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 核心蓝牙状态恢复只触发一次_Swift_Bluetooth_Bluetooth Lowenergy - Fatal编程技术网

Swift 核心蓝牙状态恢复只触发一次

Swift 核心蓝牙状态恢复只触发一次,swift,bluetooth,bluetooth-lowenergy,Swift,Bluetooth,Bluetooth Lowenergy,试图让核心蓝牙状态恢复在swift中持续工作,但我似乎只能让它启动一次,然后它就不再响应了 到目前为止,我在我的班级里有: override init() { super.init() let centralQueue = dispatch_queue_create("com.domain.app", DISPATCH_QUEUE_SERIAL) centralManager = CBCentralManager(delegate: self, queue: centra

试图让核心蓝牙状态恢复在swift中持续工作,但我似乎只能让它启动一次,然后它就不再响应了

到目前为止,我在我的班级里有:

override init() {
    super.init()
    let centralQueue = dispatch_queue_create("com.domain.app", DISPATCH_QUEUE_SERIAL)
    centralManager = CBCentralManager(delegate: self, queue: centralQueue, options: [CBCentralManagerOptionRestoreIdentifierKey: "myCentralManager", CBCentralManagerOptionShowPowerAlertKey: true]) 

}
我的遗产代表:

func centralManager(central: CBCentralManager, willRestoreState dict: [String : AnyObject]) {       

    let peripheral = dict[CBCentralManagerRestoredStatePeripheralsKey] 

    for peripheral in peripherals as! [CBPeripheral] {
        showGenericNotification("BLE \(peripheral)")
        peripheral.delegate = bleService
    }   
} 
然后,当我从BLE设备发送数据时,showNotification()会将通知放入我的通知中心。。它只发射一次,然后停止响应。bleService是具有CBPeripheralDelegate的实例,用于管理外围设备


代理似乎没有分配给bleService。。。任何人都有任何想法???

CBCentralManager
有一个方法
scanForPeripherals(带有服务:选项:)
,您可以在其中指定扫描选项。默认情况下,此管理器为接收的多个外围数据包生成一个发现事件,如中所述。您必须在
CBCentralManagerScanOptionAllowDuplicatesKey
下传递
true
值,选项字典才能获得预期效果:

每次中央接收到来自外围设备的广告包时,过滤被禁用,并生成发现事件


然后,将多次调用用于状态恢复的委托方法,但仅当必须调用该方法时,即在发现事件之间服务被禁用的情况下才会调用该方法。

CBCentralManager
有一个方法
scanForPeripherals(带有服务:options:)
用于指定扫描选项。默认情况下,此管理器为接收的多个外围数据包生成一个发现事件,如中所述。您必须在
CBCentralManagerScanOptionAllowDuplicatesKey
下传递
true
值,选项字典才能获得预期效果:

每次中央接收到来自外围设备的广告包时,过滤被禁用,并生成发现事件

然后,将多次调用用于状态恢复的委托方法,但仅当必须调用它时,即在发现事件之间服务被禁用时