RiValT_WatchDelegate
class RiValT_WatchDelegate : NSObject
extension RiValT_WatchDelegate: WCSessionDelegate
This class exists to give the Watch Connectivity a place to work.
-
This is a state code, to tell the receiver which state it should be in.
See moreDeclaration
Swift
enum TimerOperation : String, CaseIterable
-
This will describe one sync “pulse,” sent from the phone, to the Watch.
See moreDeclaration
Swift
struct SyncRecord
-
These are the types of “overall message classifications” that can be sent between peers.
See moreDeclaration
Swift
enum MessageType : String
-
This is a callback template for the message/context calls. It is always called in the main thread.
Declaration
Swift
typealias CommunicationHandler = (_ inWatchDelegate: RiValT_WatchDelegate?, _ inForceUpdate: Bool) -> Void
Parameters
inWatchDelegate
The delegate handler calling this.
inForceUpdate
True, if you want the receiver to force an update.
-
This is a callback template for errors. It is always called in the main thread.
Declaration
Swift
typealias ErrorContextHandler = (_ inWatchDelegate: RiValT_WatchDelegate?, _ inError: Error?) -> Void
Parameters
inWatchDelegate
The delegate handler calling this.
inError
Possible error. May be nil.
-
This is how many seconds we wait for a response from the phone, before giving up.
Declaration
Swift
static let testTimeoutInSeconds: TimeInterval
-
This is a timeout handler for communications with the phone.
Declaration
Swift
private var _timeoutHandler: RVS_BasicGCDTimer?
-
This is set to true, if we have received our first sync tick.
Declaration
Swift
private var _receivedFirstSync: Bool
-
This will be called when the context changes. This is always called in the main thread.
Declaration
Swift
var updateHandler: CommunicationHandler?
-
This will be called when there are errors. This is always called in the main thread.
Declaration
Swift
var errorHandler: ErrorContextHandler?
-
This is used for trying to recover from Watch sync errors.
Declaration
Swift
var retries: Int
-
This is used as the “ground truth” timer model, for both iOS, and Watch. This class keeps it synced.
Declaration
Swift
var timerModel: TimerModel
-
This maintains a reference to the session.
Declaration
Swift
var wcSession: WCSession
-
This is a simple semaphore, to indicate that an update to/from the peer is in progress.
Declaration
Swift
var isUpdateInProgress: Bool
-
This is only relevant to the Watch app. This becomes true, if we can reach the iPhone app.
Declaration
Swift
var canReachIPhoneApp: Bool
-
This is only relevant to the Watch app. If the phone is in the running timer screen, this is true.
Declaration
Swift
var isCurrentlyRunning: Bool
-
Default initializer
Declaration
Swift
init(updateHandler inUpdateHandler: CommunicationHandler? = nil, activate inActivate: Bool = true)
Parameters
inUpdateHandler
The update handler for application context update.
inActivate
If provided (default is true), and true, activation is done immediately. If false, then the activate() method needs to be called.
-
This starts a handler for a communication timeout, using our fixed timeout period.
Declaration
Swift
private func _startTimeoutHandler(completion inCompletion: @escaping ErrorContextHandler)
Parameters
inCompletion
The closure to execute, if the timeout is reached (may be called in any thread, and won’t be called, if there’s no timeout).
-
This “short circuits” the running timeout.
Declaration
Swift
private func _killTimeoutHandler()
-
This initializes the timer model.
Declaration
Swift
private func _setUpTimerModel()
-
Called for each “tick.”
Declaration
Swift
private func _tickHandler(_ inTimer: Timer)
Parameters
inTimer
The timer instance that’s “ticking.”
-
Called when the timer transitions from one state, ti another.
Declaration
Swift
private func _transitionHandler(_ inTimer: Timer, _ inFromState: TimerEngine.Mode, _ inToState: TimerEngine.Mode)
Parameters
inTimer
The timer instance that’s transitioning.
inFromState
The state that it’s transitioning from.
inToState
The state that it’s transitioning to.
-
Performs an activation
Declaration
Swift
func activate()
-
This updates the stored timer model.
Declaration
Swift
func updateSettings()
-
This sends a sync to the Watch
See moreDeclaration
Swift
func sendSync(_ inRetries: Int = 5)
-
This sends a timer operation caommand to the peer
See moreDeclaration
Swift
func sendCommand(command inCommand: TimerOperation, extraData inExtraData: String = "", _ inRetries: Int = 5)
Parameters
inCommand
The operation to send.
inExtraData
A String, with any value we wish associated with the command. Default is the command, itself.
inRetries
The number of try again retries.
-
This sends a notification, asking the user to open the iOS app.
Declaration
Swift
func promptUserToOpenApp()
-
This tries to open the app
Declaration
Swift
func openCompanionApp()
-
This is called to send the current state of the prefs to the peer.
Declaration
Swift
func sendApplicationContext()
-
This sends a message to the phone (from the watch), that is interpreted as a request for a context update.
See more
-
Just here to satisfy the protocol.
Declaration
Swift
func sessionDidBecomeInactive(_: WCSession)
-
Just here to satisfy the protocol.
Declaration
Swift
func sessionDidDeactivate(_: WCSession)
-
Called when an activation change occurs.
Declaration
Swift
func session(_ inSession: WCSession, activationDidCompleteWith inActivationState: WCSessionActivationState, error inError: (any Error)?)
Parameters
inSession
The session experiencing the activation change.
inActivationState
The new state.
inError
If there was an error, it is sent in here.
-
Called when the application context is updated from the peer.
-
Called when the Watch communication session receives a message from the peer.
Declaration
Swift
func session(_ inSession: WCSession, didReceiveMessage inMessage: [String : Any], replyHandler inReplyHandler: @escaping ([String : Any]) -> Void)
Parameters
inSession
The session receiving the message.
inMessage
The message from the watch
inReplyHandler
A function to be executed, with the reply to the message.