当我在设置中关闭蓝牙时,我使用 CBCentralManager 来获取蓝牙的状态,如下所示:
self.bluetoothManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
系统将显示如下警告:system alert
蓝牙的当前状态是CBManagerStatePoweredOff 。但是当我在控制中心关闭蓝牙时,即使蓝牙的当前状态仍然是 CBManagerStatePoweredOff ,此警报也不再显示。
在这种情况下如何提醒用户开启蓝牙?
Best Answer-推荐答案 strong>
您可以通过实现以下 delegate 方法来提醒用户。
//Bluetooth state delegation
#pragma mark - CBCentralManagerDelegate
- (void)centralManagerDidUpdateStateCBCentralManager *)central
{
NSString *stateString = nil;
switch(self.CBManager.state)
{
case CBManagerStateResetting:
stateString = @"The connection with the system service was momentarily lost, update imminent.";
break;
case CBManagerStateUnsupported:
stateString = @"The platform doesn't support Bluetooth Low Energy."; break;
case CBManagerStateUnauthorized: stateString = @"The app is not authorized to use Bluetooth Low Energy.";
break;
case CBManagerStatePoweredOff:
stateString = @"Bluetooth is currently powered off.";
break;
case CBManagerStatePoweredOn:
[self.beaconManager startMonitoringForRegion:self.museumsRegion];
[self.beaconManager startRangingBeaconsInRegion: self.museumsRegion];
break;
case CBManagerStateUnknown:
stateString = @"State unknown, update imminent.";
break;
}
NSLog(@"%@", stateString);
}
现在应该自动通知用户。
关于iOS11蓝牙有点奇怪,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/46426163/
|