1.添加 CoreBluetooth.framework框架
2.程序中.m文件引入
#import <CoreBluetooth/CoreBluetooth.h>
3.实现协议
CBPeripheralManagerDelegate,
4.添加属性:
@property (nonatomic, strong) CBPeripheralManager *manager;
5.添加以下代码到viewDidLoad方法中
self.manager=[[CBPeripheralManager alloc]initWithDelegate:self queue:nil];
6.实现代理方法:- (void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral{
switch (peripheral.state) {
case CBPeripheralManagerStatePoweredOn:
{
NSLog(@"蓝牙开启且可用");
}
break;
default:
NSLog(@"蓝牙不可用");
break;
}
}
完!