Ios 蓝牙在后台扫描
我正在制作一个关于在后台模式下扫描BLE设备并每分钟向服务器发送设备列表的应用程序 私有let uuid=CBUUIString:DEC18772-CCC0-462D-92FB-F5C823537895 self.centralManager?.scanForPeripheralswithServices:[uuid],选项:[CBCentralManagerScanOptionAllowDuplicatesKey:true] 在plist文件中Ios 蓝牙在后台扫描,ios,swift,bluetooth-lowenergy,Ios,Swift,Bluetooth Lowenergy,我正在制作一个关于在后台模式下扫描BLE设备并每分钟向服务器发送设备列表的应用程序 私有let uuid=CBUUIString:DEC18772-CCC0-462D-92FB-F5C823537895 self.centralManager?.scanForPeripheralswithServices:[uuid],选项:[CBCentralManagerScanOptionAllowDuplicatesKey:true] 在plist文件中 <array>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
我使用计时器在60秒后将设备列表发送到服务器
var timer=timer.scheduledTimertimeInterval:60,目标:self,选择器:selectorRuntimeCode,userInfo:nil,repeats:true
但当我将应用程序设置为后台模式时,一切似乎都暂停了,计时器和didDiscover回调都不起作用
让应用程序在后台模式下运行是否缺少任何东西?您在尝试执行操作时遇到了几个问题: 当你的应用程序挂起时,计时器根本不会启动;iOS上不支持使用特定时间段执行。 在后台扫描时,不能使用CBCentralManagerScanOptionAllowDuplicatesKey。 由于您在Info.plist中选择了Bluetooth background(蓝牙背景)模式,假设用户授予Bluetooth background(蓝牙背景)权限,每次看到新设备正在宣传指定的服务DEC18772-CCC0-462D-92FB-F5C823537895时,您都会收到一个didDiscover委托回调 您可以在此回调中将此设备的发现报告给服务器
当您的应用程序保留在后台时,您将不会收到该设备的任何其他委托发现回调。很抱歉,我不知道为什么CBCentralManager CanOptionalLowDuplicateSkey不能在后台使用?因为。可能允许重复通知会导致后台执行过度,并对前台应用的电池寿命和设备性能产生不利影响。