Matthias Nott
2026-04-01 f68a986682535dca139515741dd60be26a82edd6
lib/services/mqtt_service.dart
....@@ -673,6 +673,24 @@
673673 onError?.call('Cannot send message: missing sessionId');
674674 }
675675
676
+ /// Publish the APNs device token to the daemon for push notification delivery.
677
+ /// The daemon stores it in ~/.aibroker/apns-tokens.json and uses it when
678
+ /// no MQTT clients are connected (app is backgrounded or offline).
679
+ void sendDeviceToken(String token) {
680
+ final client = _client;
681
+ if (client == null || client.connectionStatus?.state != MqttConnectionState.connected) {
682
+ return;
683
+ }
684
+ try {
685
+ final builder = MqttClientPayloadBuilder();
686
+ builder.addString('{"token":"$token","ts":${DateTime.now().millisecondsSinceEpoch}}');
687
+ client.publishMessage('pailot/device/token', MqttQos.atLeastOnce, builder.payload!);
688
+ _mqttLog('Push: device token published to pailot/device/token');
689
+ } catch (e) {
690
+ _mqttLog('Push: failed to publish device token: $e');
691
+ }
692
+ }
693
+
676694 /// Disconnect intentionally.
677695 void disconnect() {
678696 _intentionalClose = true;