قالب وردپرس درنا توس
Home / IOS Development / ios – didUpdateValueFor Core Bluetooth callback function does not fire

ios – didUpdateValueFor Core Bluetooth callback function does not fire



I use Core Bluetooth in an iOS app that uses Xcode and Swift to retrieve data from a Muse 2. The process works except that the didUpdateValueFor the callback feature is not triggered. The didUpdateNotificationStateFor callback function is fired, and when I print the properties, they show that they are alerted. I've done the same thing with a Polar H1

0 and it works just fine.

One of the features has a response-free writing feature. What do I want to write about the characteristic?

Do Muse 2 Headband Manufacturers Share Information About Their Protocol?

  Import UIKit
import CoreBluetooth

class ViewController: UIViewController {

var workerQueue = DispatchQueue (label: "us.utili.TrialMuse.workerQueue")
was centralManager: CBCentralManager! = null
was muse: CBPeripheral! = null

override func viewDidLoad () {
super.viewDidLoad ()

leave options: [String: Any] = [CBCentralManagerOptionShowPowerAlertKey: true]

self.centralManager = CBCentralManager (delegate: self, queue: workerQueue, options: options)
self.centralManager.delegate = self

}


}

extension ViewController: CBCentralManagerDelegate {

func centralManagerDidUpdateState (_central: CBCentralManager) {

out ("centralManagerDidUpdateState")

switch central.state {
case. unknown:
print ("central.state is .unknown")
case. reset:
print ("central.state is resetting")
case. not supported:
print ("central.state is .unsupported")
case. authorized:
print ("central.state is. authorized")
case. poweredOff:
print ("central.state is. poweredOff")
case .poweredOn:
print ("central.state is .poweredOn")
centralManager.scanForPeripherals (withServices: nil)
@ unknown standard:
print ("change central.state @ unknown standard:")
}

}

func centralManager (_ central: CBCentralManager, didDiscover peripheral: CBPeripheral, advertisementData: [String : Any] rssi RSSI: NSNumber) {

out ("didDiscover")

print ("peripheral description:", peripheral description)

if let peripheralName = peripheral.name, peripheralName == "Muse-7EF5" {
mouse = peripheral
muse.delegate = self
central.stopScan ()
central.connect (mouse, options: null)
}

}

func centralManager (_central: CBCentralManager, didConnect peripheral: CBPeripheral) {

out ("didConnect")
print ("peripheral:", peripheral)

peripheral.discoverServices (null)

}

}

extension ViewController: CBPeripheralDelegate {

func peripheral (_ peripheral: CBPeripheral, didDiscoverServices error: Error?) {

print ("didDiscoverServices")

guard let services = peripheral services otherwise {
return
}

out ("services:")

for services in services {

print (" tservice description:", service.description)

peripheral.discoverCharacteristics (null, for: service)

}

}

func peripheral (_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {

out ("didDiscoverCharacteristicsFor")

guard let properties = service.contains other {
return
}

for characteristic features

print ("characteristic description:", character.description)

if characteristic.properties.container (.broadcast) {
out (" tbroadcast")
}
if characteristic.properties.content (.les) {
out (" tread")
}
if characteristic.properties.content (.writeWithoutResponse) {
print (" twrite without reply")
}
if characteristic.properties.content (. write) {
out (" twrite")
}
if characteristic.properties.content (. alert) {
out (" tnotify")
}
if characteristic.properties.content (.indicate) {
out (" tindicate")
}
if characteristic.properties.content (.authenticatedSIGNWrites) {
print (" tauthenticated signed signed")
}
if characteristic.properties.content (.extendedProperties) {
print (" textended properties")
}
if characteristic.properties.content (. notifyEncryptionRequired) {
print (" tnotify encryption required")
}
if characteristic.properties.content (.indicateEncryptionRequired) {
print (" tindicate encryption required")
}

if characteristic.properties.content (. alert) {
peripheral.setNotifyValue (true, for: characteristic)
}

if characteristic.properties.content (.les) {
peripheral.readValue (for: characteristic)
}

}

}

func peripheral (_ peripheral: CBPeripheral, didUpdateValueFor characteristic: CBCharacteristic, error: Error?) {

out ("didUpdateValueFor")

if let wrong = wrong {
print ("error:", error)
}

guard characteristic. value! = zero else {
return
}

print ("characteristic description:", character.description)

}

func peripheral (_ peripheral: CBPeripheral, didUpdateNotificationStateFor characteristic: CBCharacteristic, error: Error?) {

out ("didUpdateNotificationStateFor")

print ("characteristic description:", character.description)

}

}

Here is the end of the troubleshooting window:

  centralManagerDidUpdateState
central.state is. poweredOn
didDiscover
peripheral description: 
didDiscover
peripheral description: 
didConnect
peripheral: 
didDiscoverServices
services:
service description: 
didDiscoverCharacteristicsFor
characteristic description: 
write without reply
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
characteristic description: 
notify
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 
didUpdateNotificationStateFor
characteristic description: 


Source link