RiValT_BluetoothRemote

final class RiValT_BluetoothRemote : NSObject, ObservableObject
extension RiValT_BluetoothRemote: CBPeripheralManagerDelegate

A foreground iPad can vend the same request/reply protocol as the paired phone. GATT indications carry replies and change hints; each request is applied only by the host.

  • The transport shared by the timer delegate and the app’s remote settings.

    Declaration

    Swift

    static let shared: RiValT_BluetoothRemote
  • Shared device identifiers and packet framing for the Bluetooth link.

    Declaration

    Swift

    private typealias Packet = RiValT_BluetoothRemotePacket
  • The current assembly for fragments received from the remote device.

    Declaration

    Swift

    private var incoming: RiValT_BluetoothRemote.Packet.Assembly
  • The host callback that processes a complete Watch request and sends a reply.

    Declaration

    Swift

    var onRequest: (([String : Any], @escaping ([String : Any]) -> Void) -> Void)?
  • Whether the user enabled Watch Remote hosting in the iPad app.

    Declaration

    Swift

    var isEnabled: Bool { get }
  • Whether an approved Watch is subscribed to the iPad’s channel.

    Declaration

    Swift

    var hasRemoteSubscriber: Bool { get }
  • The persistent device label advertised to nearby Watches.

    Declaration

    Swift

    private(set) lazy var hostName: String { get set }
  • The Core Bluetooth peripheral manager used by the iPad.

    Declaration

    Swift

    private var manager: CBPeripheralManager?
  • The encrypted request and indication characteristic registered with the peripheral manager.

    Declaration

    Swift

    private var channel: CBMutableCharacteristic?
  • The Watch currently subscribed to the characteristic.

    Declaration

    Swift

    private var subscriber: CBCentral?
  • The pairing confirmation alert, if one is on screen.

    Declaration

    Swift

    private weak var permissionAlert: UIAlertController?
  • A localized status message when hosting needs user attention or is retrying.

    Declaration

    Swift

    @Published
    private(set) var hostingIssue: String? { get set }
  • The connected Watch’s name, or the default connected label before it provides one.

    Declaration

    Swift

    @Published
    private(set) var connectedWatchName: String? { get set }
  • The pending attempt to restart service registration or advertising.

    Declaration

    Swift

    private var hostRetry: DispatchWorkItem?
  • The delay before the next hosting retry, capped at eight seconds.

    Declaration

    Swift

    private var retryDelay: TimeInterval
  • Whether the peripheral manager confirmed registration of the service.

    Declaration

    Swift

    private var serviceAdded: Bool
  • Whether foreground and background observers have already been registered.

    Declaration

    Swift

    private var observing: Bool
  • The ordered indications waiting to be sent to the current Watch.

    Declaration

    Swift

    private var output: [Data]
  • Persists the hosting preference and starts the service or clears the approved Watch and stops it.

    Declaration

    Swift

    func setEnabled(_ enabled: Bool)
  • Registers lifecycle observers once and starts hosting on a supported iPad.

    Declaration

    Swift

    func activate()
  • Prepares the encrypted service or restarts advertising when the app is active and Bluetooth is ready.

    Declaration

    Swift

    @objc
    private func start()
  • Advertises the timer service UUID and the iPad’s persistent device label.

    Declaration

    Swift

    private func advertise()
  • Schedules a retry with backoff while the enabled host remains active and Bluetooth is on.

    Declaration

    Swift

    private func scheduleHostRetry()
  • Stops advertising, removes services, and releases subscriber and retry state.

    Declaration

    Swift

    @objc
    private func stop()
  • Clears the subscriber, displayed name, pending packets, and pairing alert.

    Declaration

    Swift

    private func releaseSubscriber()
  • Whether the subscribed Watch matches the identifier approved by the user.

    Declaration

    Swift

    private var approved: Bool { get }
  • Signals that the encrypted channel is ready and sets the default connected label.

    Declaration

    Swift

    private func confirmWatchConnection()
  • Reuses existing approval or prompts the iPad user to confirm the Watch’s displayed pairing code.

    Declaration

    Swift

    private func authorize(_ central: CBCentral)
  • Queues a single change hint for the approved Watch so it can request a fresh snapshot.

    Declaration

    Swift

    func notifyChange()
  • Appends an indication and attempts to send pending indications in order.

    Declaration

    Swift

    private func queue(_ frame: Data)
  • Sends queued indications until Core Bluetooth reports backpressure.

    Declaration

    Swift

    private func flush()
  • Starts hosting when Bluetooth becomes available or reports why it cannot run.

    Declaration

    Swift

    func peripheralManagerDidUpdateState(_ peripheral: CBPeripheralManager)
  • Starts advertising once the current service is registered or schedules a retry if registration failed.

    Declaration

    Swift

    func peripheralManager(_ peripheral: CBPeripheralManager, didAdd service: CBService, error: Error?)
  • Clears the retry status after advertising starts or schedules another attempt after a failure.

    Declaration

    Swift

    func peripheralManagerDidStartAdvertising(_ peripheral: CBPeripheralManager, error: Error?)
  • Accepts a subscription to the current channel and starts approval for the eligible Watch.

    Declaration

    Swift

    func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didSubscribeTo characteristic: CBCharacteristic)
  • Releases state when the current Watch unsubscribes from the active channel.

    Declaration

    Swift

    func peripheralManager(_ peripheral: CBPeripheralManager, central: CBCentral, didUnsubscribeFrom characteristic: CBCharacteristic)
  • Resumes sending pending indications when Core Bluetooth has capacity again.

    Declaration

    Swift

    func peripheralManagerIsReady(toUpdateSubscribers peripheral: CBPeripheralManager)
  • Accepts and assembles writes from the approved Watch and sends replies over the same channel.

    Declaration

    Swift

    func peripheralManager(_ peripheral: CBPeripheralManager, didReceiveWrite requests: [CBATTRequest])