Not able to scan Through CBCentral Manager with service ID for iBecon Signal

后端 未结 1 1053
难免孤独
难免孤独 2020-12-21 15:29

Working on iBecon signal using Core Bluetooth i am able to search with CBCentralManager scan optionn nil :-

Shared.sharedInstance.centralManager?.scanForPeri         


        
相关标签:
1条回答
  • 2020-12-21 16:04

    I am using like this, connect on button click event and use CBCentralManagerDelegate, CBPeripheralDelegate Delegate

    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)
            }
        }
    
    0 讨论(0)
提交回复
热议问题