Commands
Commands are how your app asks the Jacquard Tag to do something. Using them is straightforward:
- Construct an instance of the relevant request type. Some will require arguments (like
PlayLEDPatternCommand), others will not (likeBatteryStatusCommand). - Enqueue the request to be sent to a tag using
ConnectedTag.enqueue(_:)orConnectedTag.enqueue(_:retries:). - Observe the Combine publisher returned by one of the enqueue methods for a result or error (the request types declare an associated result type, which is the type published). Once a result is received, no more values will be published.
For example, to measure the battery status of the connected tag, assuming a published stream of the currently connected tag (see example code in Connecting to Tags).
// Observe future battery status notifications.
let subscription = BatteryStatusNotificationSubscription()
let cancellable = tagStream
.prefix(1)
.flatMap { $0.subscribe(subscription) }
.sink { [weak self] response in
guard let self = self else { return }
switch response.chargingState {
case .notCharging:
print("not charging")
case .charging:
print("charging")
}
print("battery charge: \(response.batteryLevel)%")
}
When sending comands or observing events, you should always check if the component supports that Component.capability
You can check the capabilities on a component using e.g component.capabilities.contains(.haptic)
The supported capabilties are :-
case led // = 0Gear can be used forPlayLEDPatternCommand.case gesture // = 1Gear supports gestures. i.eTouchMode.gesturecase touchDataStream // = 2Gear supports touch data stream. i.eTouchMode.touchDataStreamcase haptic // = 3Gear can be used forPlayHapticCommand.
tagPublisher
.flatMap { $0.connectedGear }
.sink { [weak self] gear in
guard let self = self else { return }
// Check if Component has supported capability to execute the co.mand.
guard let gear = gear, gear.capabilities.contains(.led) else {
return
}
}.addTo(&observers)
}
-
Types that implement this protocol describe a command request and its associated response type.
See moreSee also
CommandsDeclaration
Swift
public protocol CommandRequest -
The possible failure responses from a command.
See moreDeclaration
Swift
public enum CommandResponseStatus : Int, Error -
The possible errors published by a command.
See moreDeclaration
Swift
public enum JacquardCommandError : Error -
Declaration
Swift
public struct BatteryStatusCommand : CommandRequest -
Command to request the Gear to play an LED pattern.
Note that not all Gear components have LEDs, you can inspect
Component.capabilities.See moreSee also
CommandsDeclaration
Swift
public struct PlayLEDPatternCommand : CommandRequest -
Command to request the Gear plays a haptic pattern.
Note that the only gear Components (not the tag Component) support haptics.
See also
CommandsSee moreSee also
Components and GearDeclaration
Swift
public struct PlayHapticCommand : CommandRequest -
Declaration
Swift
public struct DisconnectTagCommand : CommandRequest -
Declaration
Swift
public struct ComponentInfoCommand : CommandRequest
View on GitHub
Commands Reference