Notifications
Notifications are how your app can observe messages sent by the Jacquard tag. Using Notifications is straightforward:
- Construct an instance of the relevant subscription type (none require arguments).
- Using the
ConnectedTag.subscribe(_:)
method on the current connected tag, construct a Combine publisher which can be used to observe notifications (which are published using the associated result type declared by the subscription type).
For example, to observe gesture notifications, assuming a published stream of the currently connected tag (see example code in Connecting to Tags).
// Observe gestures (these will not be delivered when in touchDataStream mode).
let gestureSubscription = GestureNotificationSubscription()
let cancellable = tagStream
.flatMap { $0.subscribe(gestureSubscription) }
.sink { [weak self] gesture in
guard let self = self else { return }
print("received gesture: \(gesture)")
switch gesture.touchMode {
case .brushUp, .brushIn:
print("increase something")
case .brushDown, .brushOut:
print("decrease something")
default:
print("rest easy")
}
}
-
Types that implement this protocol describe a notification subscription request and its associated notification body type.
see also:
See moreCommandRequest
Declaration
Swift
public protocol NotificationSubscription : NotificationParser
-
Notification to observe periodic
BatteryStatus
updates.There will always be one notification directly after connection.
See also
Notifications
Declaration
Swift
public struct BatteryStatusNotificationSubscription : NotificationSubscription
-
Declaration
Swift
public struct GestureNotificationSubscription : NotificationSubscription
-
Declaration
Swift
public struct ContinuousTouchNotificationSubscription : NotificationSubscription