美文网首页
iOS 蓝牙与定位是否已开启监测

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

作者: flyhao | 来源:发表于2015-12-15 10:06 被阅读4585次

蓝牙开启检测

#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;
    }
}

相关文章

网友评论

      本文标题:iOS 蓝牙与定位是否已开启监测

      本文链接:https://www.haomeiwen.com/subject/keuuhttx.html