From f68a986682535dca139515741dd60be26a82edd6 Mon Sep 17 00:00:00 2001
From: Matthias Nott <mnott@mnsoft.org>
Date: Wed, 01 Apr 2026 12:28:15 +0200
Subject: [PATCH] feat: add APNs push notification support
---
lib/services/mqtt_service.dart | 18 ++++++++++++++++++
1 files changed, 18 insertions(+), 0 deletions(-)
diff --git a/lib/services/mqtt_service.dart b/lib/services/mqtt_service.dart
index 7625e7b..b88aa31 100644
--- a/lib/services/mqtt_service.dart
+++ b/lib/services/mqtt_service.dart
@@ -673,6 +673,24 @@
onError?.call('Cannot send message: missing sessionId');
}
+ /// Publish the APNs device token to the daemon for push notification delivery.
+ /// The daemon stores it in ~/.aibroker/apns-tokens.json and uses it when
+ /// no MQTT clients are connected (app is backgrounded or offline).
+ void sendDeviceToken(String token) {
+ final client = _client;
+ if (client == null || client.connectionStatus?.state != MqttConnectionState.connected) {
+ return;
+ }
+ try {
+ final builder = MqttClientPayloadBuilder();
+ builder.addString('{"token":"$token","ts":${DateTime.now().millisecondsSinceEpoch}}');
+ client.publishMessage('pailot/device/token', MqttQos.atLeastOnce, builder.payload!);
+ _mqttLog('Push: device token published to pailot/device/token');
+ } catch (e) {
+ _mqttLog('Push: failed to publish device token: $e');
+ }
+ }
+
/// Disconnect intentionally.
void disconnect() {
_intentionalClose = true;
--
Gitblit v1.3.1