Subscribing to notifications for characteristics from different services is not working as expected on Darwin platforms (iOS and macOS).
Expected Behavior
I'd expect for the notification handler to be triggered for all of the characteristics I subscribe to, even if those characteristics are from different services.
Observed Behavior
Only the last characteristics I subscribe to from a single service have the notification handlers called.
The Cache stores Services and Characteristics as siblings. The Characteristics are stored by the index / order that they were discovered in.
This means that if you discover characteristics from Service A. Then discover characteristics from Service B. The characteristics from Service B overwrite the characteristics from Service A.
Issue
Subscribing to notifications for characteristics from different services is not working as expected on Darwin platforms (iOS and macOS).
Expected Behavior
I'd expect for the notification handler to be triggered for all of the characteristics I subscribe to, even if those characteristics are from different services.
Observed Behavior
Only the last characteristics I subscribe to from a single service have the notification handlers called.
Possible Cause
I've done some initial investigation and the cause of this limitation may live in the
Cache
ofDarwinCentral.swift
: https://github.com/PureSwift/GATT/blob/5752c678e2c723d22112c04477157fc5116863dd/Sources/DarwinGATT/DarwinCentral.swift#L781-L823The
Cache
storesServices
andCharacteristics
as siblings. TheCharacteristics
are stored by the index / order that they were discovered in.This means that if you discover characteristics from Service A. Then discover characteristics from Service B. The characteristics from Service B overwrite the characteristics from Service A.
Additional Information
Depending on how the caller discovers / subscribes to notifications, this may result in an
Invalid characteristic
assertion failure when attempting to call the notification handlers: https://github.com/PureSwift/GATT/blob/5752c678e2c723d22112c04477157fc5116863dd/Sources/DarwinGATT/DarwinCentral.swift#L595-L598