Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Live activity with Firebase cloud messaging FCM #110

Open
hosain-mohamed opened this issue Dec 19, 2024 · 1 comment
Open

Update Live activity with Firebase cloud messaging FCM #110

hosain-mohamed opened this issue Dec 19, 2024 · 1 comment

Comments

@hosain-mohamed
Copy link

The new FCM feature with live activity.

After setting the activityToken to the live_activity_token as present in the picture

Screenshot 2024-12-19 at 7 57 54 PM

The live activity didn't updated.

Note : the content-state contain keys that present in the use defaults

What should be included in the content-state & live_activity_token to make it work instead?

@Clon1998
Copy link
Contributor

If we are talking about creating a LA:

The live_activity_token is the pushToStartTokenUpdates.

If I understand the code correctly @istornz added a section to monitor that token but its never transported to flutter.

The content state reflects the mutable state of the activity.


If we are talking bout updating a LA:

The live_activity_token is the token you received from the activityUpdateStream which provides the token after you called createActivity.

The content state is still the mutable content of your activity. In my case:

struct LiveActivitiesAppAttributes: ActivityAttributes, Identifiable {
    public typealias LiveDeliveryData = ContentState // don't forget to add this line, otherwise, live activity will not display it.
    
    public struct ContentState: Codable, Hashable {
        // make everything nullable to be able to retrieve initial
        // values before notification is sent to update
        let progress: Double?
        let eta: Int?
        let printState: String?
        let file: String?
    }
    
    var id = UUID()
}

This will be the progress, eta, printState and file properties.
I am using APNs directly, as FCM did not support LA while I developed my solution, I send a Map<String, String> with the field -> newValue (e.g. progress : "1") mappings to the APNs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants