iOS版 - 检查蓝牙是在没有系统警报弹出用户 [英] iOS - check if bluetooth is on without system alert popup to user

查看:878
本文介绍了iOS版 - 检查蓝牙是在没有系统警报弹出用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这code可让来确定当前的蓝牙状态:

This code allows to determine current bluetooth status:

CBCentralManager* testBluetooth = [[CBCentralManager alloc] initWithDelegate:nil queue: nil];


switch ([testBluetooth state]) {....}

但是,当的 [CBCentralManager页头]初始化...] 的情况发生,系统弹窗警告用户,如果蓝牙关闭。

But, when [[CBCentralManager alloc] init...] happens, system popups an alert to user, if bluetooth is off.

有没有什么办法来检查蓝牙状态,而不会干扰我的用户?

推荐答案

我得到了以下从苹果开发者的反应:在iOS7中, CBCentralManagerOptionShowPowerAlertKey 选项,可以禁用此警报。

I got the following response from an apple developer : In iOS7, the CBCentralManagerOptionShowPowerAlertKey option lets you disable this alert.

如果您havea一个CBCentralManager当你初始化它,你可以使用的方法 initWithDelegate:队列:选项

If you havea a CBCentralManager when you initialise it, you can use the method initWithDelegate:queue:options

例如:

在我.h文件中,我有一个 CBCentralManager *经理

In my .h file i have a CBCentralManager * manager

在.m文件:

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:NO], CBCentralManagerOptionShowPowerAlertKey, nil];

_manager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:options];

[_manager scanForPeripheralsWithServices:nil options:nil];

有了这个code警告不再出现,我希望帮助!

With this code the warning no longer appears, I hope that helps !

这篇关于iOS版 - 检查蓝牙是在没有系统警报弹出用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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