iOS:在后台模式下未调用didDiscoverPeripheral [英] iOS: didDiscoverPeripheral not called in Background mode

查看:142
本文介绍了iOS:在后台模式下未调用didDiscoverPeripheral的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究BLE项目,当应用程序位于前台时,一切正常。它可以发现并连接到外围设备,所有回叫方法都能正常工作。



<但问题是,当应用程序处于后台模式时(我按下主页按钮)。只调用 centralManagerDidUpdateState 委托方法。

   - (void)centralManagerDidUpdateState:(CBCentralManager *)central {
switch(central.state){
case CBCentralManagerStatePoweredOn:
[self.cbCentralManager scanForPeripheralsWithServices:nil options:@ {CBCentralManagerScanOptionAllowDuplicatesKey:@YES}];
休息;
默认值:
break;
}
}

我使用 scanForPeripheralsWithServices:nil 选项,但当应用程序在后台时, didDiscoverPeripheral 回调永远不会被调用。我用bluetooth-central选项编辑我的plist文件,以支持后台的中心角色。



任何想法为什么 didDiscoverPeripheral 方法在后台应用时不调用?

解决方案

Paulw11说是对的,如果你的应用找到了外围设备前景。当它进入后台时,它不会为相同的外围设备调用 didDiscoverPeripheral



有关iOS的更多信息BLE在后台模式下的行为。你可以查看这个答案
CoreBluetooth应用程序在后台可以做什么?


I am Working on BLE project, everything works fine when the app in the foreground.It can discover and connect to the peripheral, all the call back method work perfectly.

But the problem is that, when the app in the background mode (I press home button). Only the centralManagerDidUpdateState delegate method get called.

- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
    switch (central.state) {
        case CBCentralManagerStatePoweredOn:
          [self.cbCentralManager scanForPeripheralsWithServices:nil options:@{ CBCentralManagerScanOptionAllowDuplicatesKey : @YES }];
            break;
        default:
            break;
    }
}

I use scanForPeripheralsWithServices:nil option, But when the app in the background, the didDiscoverPeripheral call back never called. I have edit my plist file with "bluetooth-central" option to support ble central role in background.

Any idea why didDiscoverPeripheral method not call when app in the background?

解决方案

Paulw11 said are right, If your app find the peripherals in the foreground. It will not call the didDiscoverPeripheral for the same peripherals when it enters the background.

For more information about the iOS BLE Behavior in the background mode. You can check this answer What exactly can CoreBluetooth applications do whilst in the background?

这篇关于iOS:在后台模式下未调用didDiscoverPeripheral的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆