**系统要求:IOS7.0开始支持BLE,但是这里使用swift语言,swift是需要IOS8.0以上,所以,这里系统都是IOS8.0以上
硬件要求:iphone 4s以上(包含4s),才有BLE硬件。**
1.先获取到一个蓝牙的manager:
// BLE需要蓝牙库支持,所以,需要导入蓝牙框架
import CoreBluetooth
manager = CBCentralManager(delegate: self, queue: nil);
这里delegate需要实现以下方法:
// 蓝牙启用状态,这个回调会在创建manger时回调
func centralManagerDidUpdateState(central: CBCentralManager){
if(central.state == CBCentralManagerState.PoweredOn){ // 可以使用
}
}
2.扫描蓝牙:
manager?.scanForPeripheralsWithServices(nil, options: nil); // 这里是没有设置过滤方法,如果需要过滤特定设备,可以在这里添加特定的uuid
// 扫描回调
func centralManager(central: CBCentralManager, didDiscoverPeripheral peripheral: CBPeripheral,