firebase-admin-dotnet icon indicating copy to clipboard operation
firebase-admin-dotnet copied to clipboard

iOS Live Activity support

Open alex-radch opened this issue 1 year ago • 1 comments

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

alex-radch avatar Nov 29 '24 10:11 alex-radch

I found a few problems with this issue:

  • I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.
  • This issue does not seem to follow the issue template. Make sure you provide all the required information.

google-oss-bot avatar Nov 29 '24 10:11 google-oss-bot

This feature is now available in Admin .NET v3.3.0

jonathanedey avatar Jul 09 '25 18:07 jonathanedey