didDisconnectPeripheral
全部标签 我有一个CoreBluetooth应用程序。这会在前台启动连接并开始发送/接收数据,并在发送到后台时继续执行此操作,因为我已将bluetooth-central添加到app-Info中的UIBackgroundModes。plist。如果我切换飞行模式设置,我的应用会断开连接,但它不会获得didDisconnectPeripheral回调。为什么是这样?我的解决方法是清除centralManagerDidUpdateState中对我的CBPeriperal对象的所有引用,以便能够在应用程序再次进入前台时进行新的扫描和连接. 最佳答案
我正在使用蓝牙LE(4.0)和CoreBluetooth框架创建一个iOS(7.1)应用程序,使设备充当“外围设备”。我可以使用另一台充当“Central”的iOS设备连接到该应用程序,以探索其服务和特性。但是,一旦建立连接,连接会在建立连接后30秒到1分钟之间随机断开,我不知道为什么。当我检查委托(delegate)方法时:-(void)centralManager:(CBCentralManager*)centraldidDisconnectPeripheral:(CBPeripheral*)aPeripheralerror:(NSError*)error错误信息是“指定的设备已与
我有一个自定义对象BLEDevice,它对CBPeripheral对象有弱引用。我维护了一个字典,用于保存外围设备和我的自定义对象之间的关联:-(void)setDeviceForPeripheral:(CBPeripheral*)peripheral{//Newdevice:setsanew'BLEDevice'instanceBLEDevice*new=[[BLEDevicealloc]initWithPeripheral:peripheral];new.name=peripheral.name;new.peripheral.delegate=self;[associationss