Skip to content

iOS Live Activity support #440

@alex-radch

Description

@alex-radch

Recently Firebase introduce support for iOS Live Activity feature
I tried to implement this with CustomData properties in ApnsConfig and Aps classes like this (used 3.1.0 version in Nuget):

	private const string UpdateEvent = "update";
	private const string EndEvent = "end";

	public async Task<string> Test(string token, string liveActivityToken, Dictionary<string, object> data, bool end = false)
	{
		var now = DateTime.UtcNow;
		var liveActivityData = new Dictionary<string, object>
		{
			{ "timestamp", now.ToUnixTimeStamp() },
			{ "event", end ? EndEvent : UpdateEvent },
			{ "content-state", data }
		};
		if (end)
			liveActivityData.Add("dismissal-date", now.AddSeconds(60).ToUnixTimeStamp());

		var message = new Message
		{
			Token = token,
			Apns = new ApnsConfig
			{
				Headers = new Dictionary<string, string>() { ["apns-priority"] = "10" },
				CustomData = new Dictionary<string, object>() { ["live_activity_token"] = liveActivityToken },
				Aps = new Aps { CustomData = liveActivityData }
			}
		};
		return await FirebaseMessaging.DefaultInstance.SendAsync(message, false);
	}

But it fails with error:

FirebaseAdmin.Messaging.FirebaseMessagingException: Request contains an invalid argument.
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndReadAsync(HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Util.ErrorHandlingHttpClient`1.SendAndDeserializeAsync[TResult](HttpRequestMessage request, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessagingClient.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun, CancellationToken cancellationToken)
   at FirebaseAdmin.Messaging.FirebaseMessaging.SendAsync(Message message, Boolean dryRun)

After some debugging I found what send .NET Admin SDK in request:

{
    "message": {
        "token": "fcmToken",
        "apns": {
            "headers": {
                "apns-priority": "10"
            },
            "payload": {
                "aps": {
                    "timestamp": 1732875252,
                    "event": "update",
                    "content-state": {
                        "someField": "someValue"
                    }
                },
                "live_activity_token": "liveActivityToken" // bad
            }
        }
    },
    "validate_only": false
}

But Firebase waits request like this (live_activity_token needs to be in apns, not in apns.payload):

{
    "message": {
        "token": "fcmToken",
        "apns": {
            "live_activity_token": "liveActivityToken", // good
            "headers": {
                "apns-priority": "10"
            },
            "payload": {
                "aps": {
                    "timestamp": 1732875252,
                    "event": "update",
                    "content-state": {
                        "someField": "someValue"
                    }
                }
            }
        }
    },
    "validate_only": false // probably doesn't matter
}

So I have 2 questions:

  1. can I do some workarounds in current Nuget version of Admin SDK to move live_activity_token field into apns object?
  2. will you be adding support for this feature to the SDK? Probably with new properties in appropriate models

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions