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

iOS Live Activity support #440

Open
alex-radch opened this issue Nov 29, 2024 · 1 comment
Open

iOS Live Activity support #440

alex-radch opened this issue Nov 29, 2024 · 1 comment

Comments

@alex-radch
Copy link

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
@google-oss-bot
Copy link

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.

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

No branches or pull requests

2 participants