Shared.sharedInstance.centralManager?.scanForperipherals(withServices: nil,options:[CBCentralManagerScanoptionAllowDuplicatesKey:true])
但是,当我提供我理想的服务ID,即: –
Shared.sharedInstance.centralManager?.scanForperipherals(withServices: [serviceID],options:[CBCentralManagerScanoptionAllowDuplicatesKey:true])
它从不调用dIDdiscoverPeripheral Delegate方法,我也需要在后台模式下扫描外设,并且根据Apple文档,您需要在需要在后台模式下扫描时明确提供服务ID.任何人都可以帮助我在这里做错事.
解决方法 我这样用,连接按钮单击事件
并使用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) } }总结
以上是内存溢出为你收集整理的ios – 无法通过CBCentral Manager扫描iBecon信号的服务ID全部内容,希望文章能够帮你解决ios – 无法通过CBCentral Manager扫描iBecon信号的服务ID所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)