1.添加 CoreBluetooth.framework框架
2.程序中.m文件引入
#import
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;
}
}