不断地显示;打开蓝牙以允许应用程序连接到附件;ios中后台的警报消息
我正在我的应用程序中使用iBeacon技术。我正在应用程序中检查用户是否启用或禁用蓝牙,为此我在下面编写了代码不断地显示;打开蓝牙以允许应用程序连接到附件;ios中后台的警报消息,ios,bluetooth,core-bluetooth,Ios,Bluetooth,Core Bluetooth,我正在我的应用程序中使用iBeacon技术。我正在应用程序中检查用户是否启用或禁用蓝牙,为此我在下面编写了代码 - (void)viewDidLoad { [super viewDidLoad]; _bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil]; } // bluetooth manager state change - (void)ce
- (void)viewDidLoad
{
[super viewDidLoad];
_bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
}
// bluetooth manager state change
- (void)centralManagerDidUpdateState:(CBCentralManager *)central
{
NSString *stateString = nil;
switch(central.state)
{
case CBCentralManagerStateResetting: stateString = @"The connection with the system service was momentarily lost, update imminent."; break;
case CBCentralManagerStateUnsupported: stateString = @"The platform doesn't support Bluetooth Low Energy."; break;
case CBCentralManagerStateUnauthorized: stateString = @"The app is not authorized to use Bluetooth Low Energy."; break;
case CBCentralManagerStatePoweredOff: stateString = @"Bluetooth is currently powered off."; break;
case CBCentralManagerStatePoweredOn: stateString = @"Bluetooth is currently powered on and available to use."; break;
default: stateString = @"State unknown, update imminent."; break;
}
}
问题:在后台或其他应用程序打开时,即使我已关闭该应用程序,上述警告消息也会频繁提示。我想显示此默认警报消息,但仅在用户打开应用程序时显示
谁能给我一个解决方案
self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self
queue:nil
options:@{CBCentralManagerOptionShowPowerAlertKey: @NO}];
这可能用于隐藏系统弹出窗口。您确定没有在其他地方访问蓝牙吗?ViewDidLoad仅应在加载视图控制器时激发。你为你的应用设置了什么背景模式(如果有的话)?是的,我只使用蓝牙来检查它是启用还是禁用。我已经启用了。在功能中,仅启用远程通知。我想,我在ios 8中遇到了这个问题。你应该尝试删除showPowerAlertKey的选项,如果这无助于在你的应用进入后台时使用通知观察员来释放你的中央管理器。首先,我在没有此showPowerAlertKey选项的情况下尝试了此选项,但也没有效果。我想显示此警报,以便用户可以轻松导航到蓝牙设置选项。可能无法将用户导航到蓝牙设置,您可以通过文本或特殊UI向用户发出警报,当代理回调
central.state
为case CBCentralManagerStatePoweredOff
时,您将看到self.bluetoothManager=CBCentralManager(代理:self,队列:nil,选项:[CBCentralManagementShowPowerAlertKey:false])