iOS 蓝牙与定位是否已开启监测

蓝牙开启检测

#import <CoreLocation/CoreLocation.h>
@interface GetLocation()<CLLocationManagerDelegate>
{
  CLLocationManager * _locationManager;
}

@implementation GetLocation

-(void)init{
        //判断用户定位服务是否开启
        if ([CLLocationManager locationServicesEnabled]) {
            //开始定位用户的位置
            [_locationManager startUpdatingLocation];
            //每隔多少米定位一次(这里的设置为任何的移动)
            _locationManager.distanceFilter=kCLDistanceFilterNone;
            _locationManager.desiredAccuracy=kCLLocationAccuracyBestForNavigation;
        }else{
                 //不能定位用户的位置
                 //1.提醒用户检查当前的网络状况
                 //2.提醒用户打开定位开关
        }
}
@end

定位开启检测

@interface BlueToothState()<CLLocationManagerDelegate>
// 蓝牙检测
@property (nonatomic,strong)CBCentralManager *centralManager;

@implementation GetLocation
-(void)viewDidLoad{
 // 蓝牙检测
    self.centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil options:nil];
}

#pragma mark - CLLocationManagerDelegate
-(void)centralManagerDidUpdateState:(CBCentralManager *)central
{
    //第一次打开或者每次蓝牙状态改变都会调用这个函数
    if(central.state==CBCentralManagerStatePoweredOn)
    {
        NSLog(@"蓝牙设备开着");
        self.blueToothOpen = YES;
    }
    else
    {
        NSLog(@"蓝牙设备关着");
        self.blueToothOpen = NO;
    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容