1.导入头文件
#import <CoreBluetooth/CoreBluetooth.h>
@property(strong,nonatomic)CBCentralManager* CM;
3.遵守代理方法
CBCentralManagerDelegate
4.初始化对象,设置代理
self.CM = [[CBCentralManageralloc] initWithDelegate:selfqueue:nil];
5.代理方法
- (void)centralManagerDidUpdateState:(CBCentralManager *)central{
NSString *message = nil;
switch (central.state) {
case 1:
message = @"该设备不支持蓝牙功能,请检查系统设置";
break;
case 2:
message = @"该设备蓝牙未授权,请检查系统设置";
break;
case 3:
message = @"该设备蓝牙未授权,请检查系统设置";
break;
case 4:
message = @"该设备尚未打开蓝牙,请在设置中打开";
break;
case 5:
message = @"蓝牙已经成功开启,请稍后再试";
break;
default:
break;
}
if(message!=nil&&message.length!=0)
{
NSLog(@"message == %@",message);
}
}