当CBCentralManager的状态不断上电,但仍然给我一个"在&QUOT未通电;警告? [英] When would CBCentralManager's state ever be powered on but still give me a "not powered on" warning?

查看:193
本文介绍了当CBCentralManager的状态不断上电,但仍然给我一个"在&QUOT未通电;警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直当我运行我的应用程序,在iPhone 5采用CoreBluetooth收到此错误:< CBConcreteCentralManager:0x2007d590>未开启

I keep getting this error when I run my app that uses CoreBluetooth on an iPhone 5: <CBConcreteCentralManager: 0x2007d590> is not powered on

我的程序的唯一CBCentralManager对象但当我打电话状态,它返回5,这是CBCentralManagerStatePoweredOn。所以它的开机,但我得到这个错误。还启用了iPhone的蓝牙。

But when I call state on my program's one and only CBCentralManager object, it returns 5, which is CBCentralManagerStatePoweredOn. So it's powered on, yet I get this error. The iPhone's Bluetooth is also enabled.

就在一般情况下,当将这种不会发生?我甚至不知道什么是在程序运行,因为我得到什么样子相互矛盾的信息要去。

Just in general, when would this ever happen? I don't even know what is going on when the program runs because I'm getting what looks like conflicting messages.

推荐答案

您必须首先等到centralManager会从 centralManagerDidUpdateState回调:当你启动应用程序向上。然后每个其他时间,我建议做任何centralManager调用之前检查状态。你最有可能调用扫描或检索中央有机会更新之前。确保你只调用方法你知道这是后。如果包装如果首先检查状态报表每个调用,你不会得到错误。

You have to initially wait until the centralManager gets the callback from centralManagerDidUpdateState: when you're app boots up. Then every other time, I recommend checking the state prior to doing any centralManager calls. You're most likely calling scan or retrieve before the central has had a chance to update. Ensure you only call methods after you know it's on. You will not get the error if you wrap each call in if statements that check the state first.

- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
   if(central.state==CBCentralManagerStatePoweredOn)
   {
      //Now do your scanning and retrievals
   }
}

否则只是包装您的中心每次调用之前的状态检查里面的:

Otherwise just wrap your central inside a state check before each call:

if(yourCentral.state==CBCentralManagerStatePoweredOn)
{
//you're good to go on calling centralManager methods
}

这篇关于当CBCentralManager的状态不断上电,但仍然给我一个&QUOT;在&QUOT未通电;警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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