ios - Bluetooth BLE Device disconnects as soon as connected? -
i've been writing app using swift connects bluetooth ble device. reason, app doesn't connect device. in case connect gets disconnected straight away. happens maybe 1 in 10 times connects, interferes reliability of app. i'm using corebluetooth
connect ble device. attempting connection again gets reconnect, , other apps communicate device works correctly every time, i'm confident not problem peripheral.
i'd know if there out there has had similar issue or if there particular reason why may happening?
edit: here's code willselectrow of table. peripheral connect.
func tableview(tableview: uitableview, willselectrowatindexpath indexpath: nsindexpath) -> nsindexpath? { centralmanager.stopscan() connectingperipheral.append(discovereddevicearrayinfo[indexpath.row]) connectperipheralnow(connectingperipheral[0]) return indexpath }
this connect, @ point select row sets cbperipheral details of device connect to.
connectperipheralnow looks this:
func connectperipheralnow(peripheral: cbperipheral!){ self.centralmanager.connectperipheral(peripheral, options: nil) }
didconnectperipheral , diddiscoverservices looks this
func centralmanager(central: cbcentralmanager,didconnectperipheral peripheral: cbperipheral) { peripheral.delegate = self peripheral.discoverservices([cbuuid(string: "ffe5")]) print("success: connected " + peripheral.name!) } func peripheral(peripheral: cbperipheral, diddiscoverservices error: nserror?) { if let serviceperipherals = peripheral.services [cbservice]! { serviceperipheral in serviceperipherals { print("information: service discovered " + string(stringinterpolationsegment: serviceperipheral.uuid)) peripheral.discovercharacteristics(nil, forservice: serviceperipheral) } } }
just info, 'success: connected xxx' message appear shows connecting. if need more code, let me know!
what mentioning more of expected behaviour. btle designed consume little amount of energy drops connection possible. if not need permanent connection follow discover --> connect --> read/write --> setup timer --> when timer fires connect.
if need permanent connection, should subscribe characteristic transmits real time data heart rate application. need implement setnotifyvalue:forcharacteristic:
method. read apple documentation more details.
Comments
Post a Comment