Enhance Live Activity dismissal handling by passing deviceId and updating server unregistration logic

This commit is contained in:
2026-03-06 11:14:07 +01:00
parent e857f10073
commit fe33bb2db0
5 changed files with 21 additions and 8 deletions

View File

@@ -38,7 +38,10 @@ import Security
object: nil,
queue: .main
) { [weak self] _ in
self?.methodChannel?.invokeMethod("liveActivityDismissed", arguments: nil)
let deviceId = self?.getOrCreateDeviceId() ?? ""
self?.methodChannel?.invokeMethod("liveActivityDismissed", arguments: [
"deviceId": deviceId,
])
}
// Token rotation figyelése: ha az APNs új tokent ad, értesítjük Flutter-t

View File

@@ -95,6 +95,8 @@ final class LiveActivityManager {
name: NSNotification.Name("LiveActivityDismissed"),
object: nil
)
// Activity formálisan is leállítjuk ha még fut
await activity.end(nil, dismissalPolicy: .immediate)
break
}
}

View File

@@ -73,9 +73,9 @@ class LiveCardProvider extends ChangeNotifier {
};
// Ha a user dismiss-eli a Live Activity-t (swipe), értesítjük a szervert
PlatformChannel.onActivityDismissed = () {
PlatformChannel.onActivityDismissed = (deviceId) {
debugPrint("Live Activity dismissed - unregistering from server");
serverSync.unregister();
serverSync.forceUnregister(deviceId);
hasActivityStarted = false;
hasUserDismissed = true;
};

View File

@@ -10,7 +10,7 @@ class PlatformChannel {
static void Function(String pushToken, String deviceId, String bundleId)? onTokenUpdated;
/// Callback ha a user dismiss-eli a Live Activity-t (swipe left).
static void Function()? onActivityDismissed;
static void Function(String deviceId)? onActivityDismissed;
static void _setupMethodCallListener() {
_channel.setMethodCallHandler((call) async {
@@ -24,8 +24,10 @@ class PlatformChannel {
);
}
} else if (call.method == 'liveActivityDismissed') {
debugPrint("Live Activity dismissed by user");
onActivityDismissed?.call();
final args = call.arguments as Map?;
final deviceId = args?['deviceId'] as String? ?? '';
debugPrint("Live Activity dismissed by user (device: $deviceId)");
onActivityDismissed?.call(deviceId);
}
});
}

View File

@@ -119,20 +119,26 @@ class ServerSyncProvider {
Future<void> unregister() async {
if (_deviceId == null) return;
await forceUnregister(_deviceId!);
}
/// Unregister egy adott deviceId-vel, akkor is ha a _deviceId nincs beállítva (pl. app restart után).
Future<void> forceUnregister(String deviceId) async {
try {
final response = await http.post(
Uri.parse('$_baseUrl/unregister'),
headers: {'Content-Type': 'application/json'},
body: jsonEncode({'device_id': _deviceId}),
body: jsonEncode({'device_id': deviceId}),
).timeout(const Duration(seconds: 10));
if (response.statusCode == 200) {
debugPrint('ServerSync: schedule törölve (unregister)');
debugPrint('ServerSync: device + schedule törölve (unregister)');
} else {
debugPrint('ServerSync unregister hiba: ${response.statusCode}');
}
} catch (e) {
debugPrint('ServerSync unregister kivétel: $e');
}
_deviceId = null;
}
List<Lesson> _filterLessons(List<Lesson> lessons) {