此代码允许确定当前的蓝牙状态:
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@使用此代码,警告不再出现,我希望有帮助!