无法使用iBecon Signal的服务ID扫描CBCentral Manager

使用核心蓝牙处理iBecon信号,我可以使用CBCentralManager扫描选项nil进行search: –

Shared.sharedInstance.centralManager?.scanForPeripherals(withServices: nil, options:[CBCentralManagerScanOptionAllowDuplicatesKey:true]) 

但是当我提供我想要的服务ID即:

 Shared.sharedInstance.centralManager?.scanForPeripherals(withServices: [serviceID], options:[CBCentralManagerScanOptionAllowDuplicatesKey:true]) 

它永远不会调用didDiscoverPeripheral Delegate方法,我也需要在后台模式下扫描外围设备,根据苹果文档,您需要明确提供服务ID,无论何时需要在后台模式下扫描。 任何人都可以帮助我在这里做错了什么。

我正在使用像这样,连接上button单击事件,并使用CBCentralManagerDelegate, CBPeripheralDelegate委托

 func connectDevice(sender:UIButton){ if peripheral != nil { manager.cancelPeripheralConnection(peripheral) manager = CBCentralManager(delegate: self, queue: nil) } } func centralManagerDidUpdateState(central: CBCentralManager) { if central.state == CBCentralManagerState.PoweredOn { central.scanForPeripheralsWithServices(nil, options: nil) } else { self.showAlert(Messages().alert , message: "Bluetooth is not on.") } } func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral, advertisementData: [String : AnyObject], RSSI: NSNumber) { let device = (advertisementData as NSDictionary).objectForKey(CBAdvertisementDataLocalNameKey) as? NSString print(device) if device?.containsString(BEAN_NAME) == true { self.manager.stopScan() self.peripheral = peripheral self.peripheral.delegate = self manager.connectPeripheral(peripheral, options: nil) } }