1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Flutter] Unable to Update Live Activities in Background and Lock Screen Using FCM Push...

Discussão em 'Mobile' iniciado por Stack, Outubro 22, 2024 às 04:13.

  1. Stack

    Stack Membro Participativo

    I'm working on a Flutter application that uses Firebase Cloud Messaging (FCM) to send push notifications. I want to update live activities whenever I receive a push notification, but I'm facing an issue where the live activities are not updating when the app is in the background or on the lock screen.

    Here’s a simplified version of my code:

    FirebaseMessaging.onMessage.listen((message) async {
    final notification = message.notification;
    if (Platform.isIOS) {
    final _liveActivitiesPlugin = LiveActivities();
    _liveActivitiesPlugin.init(appGroupId: "group.new_activity");

    SharedPreferences prefs = await SharedPreferences.getInstance();
    String? activityId = prefs.getString('liveActivityId');

    if (activityId != null) {
    await _liveActivitiesPlugin.updateActivity(
    activityId,
    {'soc': '${++soc}'},
    );
    }
    }


    int soc = 0;
    Future<void> handleBackgroundMessage(RemoteMessage message) async {
    print('Title: ${message.notification?.title}');
    print('body: ${message.notification?.body}');
    print('Payload: ${message.data}');
    if (Platform.isIOS) {
    final _liveActivitiesPlugin = LiveActivities();
    _liveActivitiesPlugin.init(appGroupId: "group.new_activity");
    SharedPreferences prefs = await SharedPreferences.getInstance();
    String? activityId = prefs.getString('liveActivityId');
    if (activityId != null) {
    await _liveActivitiesPlugin.updateActivity(
    activityId,
    {'soc': '${++soc}'},
    );
    }
    }
    }

    Problem:


    I am trying to update the live activities using FCM push notifications, but it is not updating when the app is in the background or on the lock screen.

    Continue reading...

Compartilhe esta Página