藍(lán)牙開(kāi)啟檢測(cè)
#import <CoreLocation/CoreLocation.h>
@interface GetLocation()<CLLocationManagerDelegate>
{
CLLocationManager * _locationManager;
}
@implementation GetLocation
-(void)init{
//判斷用戶定位服務(wù)是否開(kāi)啟
if ([CLLocationManager locationServicesEnabled]) {
//開(kāi)始定位用戶的位置
[_locationManager startUpdatingLocation];
//每隔多少米定位一次(這里的設(shè)置為任何的移動(dòng))
_locationManager.distanceFilter=kCLDistanceFilterNone;
_locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
}else{
//不能定位用戶的位置
//1.提醒用戶檢查當(dāng)前的網(wǎng)絡(luò)狀況
//2.提醒用戶打開(kāi)定位開(kāi)關(guān)
}
}
@end
定位開(kāi)啟檢測(cè)
@interface BlueToothState()<CLLocationManagerDelegate>
// 藍(lán)牙檢測(cè)
@property (nonatomic,strong)CBCentralManager *centralManager;
@implementation GetLocation
-(void)viewDidLoad{
// 藍(lán)牙檢測(cè)
self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
}
#pragma mark - CLLocationManagerDelegate
-(void)centralManagerDidUpdateState:(CBCentralManager *)central
{
//第一次打開(kāi)或者每次藍(lán)牙狀態(tài)改變都會(huì)調(diào)用這個(gè)函數(shù)
if(central.state==CBCentralManagerStatePoweredOn)
{
NSLog(@"藍(lán)牙設(shè)備開(kāi)著");
self.blueToothOpen = YES;
}
else
{
NSLog(@"藍(lán)牙設(shè)備關(guān)著");
self.blueToothOpen = NO;
}
}