iOS – 检查蓝牙是否打开而没有系统警报弹出窗口给用户

前端之家收集整理的这篇文章主要介绍了iOS – 检查蓝牙是否打开而没有系统警报弹出窗口给用户前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
代码允许确定当前的蓝牙状态:
CBCentralManager* testBluetooth = [[CBCentralManager alloc] initWithDelegate:nil queue: nil];


switch ([testBluetooth state]) {....}
@H_404_4@但是,当[[CBCentralManager alloc] init …]发生时,如果蓝牙关闭,系统会向用户弹出警报.

@H_404_4@有没有办法检查蓝牙状态,而不打扰我的用户

解决方法

我从苹果开发人员得到以下回应:在iOS7中,CBCentralManagerOptionShowPowerAlertKey选项可以禁用此警报. @H_404_4@如果您在初始化时具有CBCentralManager,则可以使用initWithDelegate方法:queue:options

@H_404_4@例:

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

@H_404_4@在.m文件中:

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

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

[_manager scanForPeripheralsWithServices:nil options:nil];
@H_404_4@使用此代码,警告不再出现,我希望有帮助!

猜你在找的iOS相关文章