firebase / firebase-admin-dotnet

Firebase Admin .NET SDK
https://firebase.google.com/docs/admin/setup
Apache License 2.0
366 stars 131 forks source link

FirebaseMessaging to iOS stopped working, status=Faulted #288

Closed chrwei closed 3 years ago

chrwei commented 3 years ago

.net 4.6.1, FirebaseAdmin v2.0.0 from nuget

I had this all working about a month ago. At some point it stopped sending iOS notifications, but Android still works.

                Message m = new Message() {
                    Android = new AndroidConfig() {
                        Priority = Priority.High,
                        Notification = new AndroidNotification() {
                            Sound = "default"
                        }
                    },
                    Notification = new Notification() {
                        Title = msg.title,
                        Body = msg.body
                    },
                    Apns = new ApnsConfig() {
                        Aps = new Aps() {
                            Badge = 1,
                            Sound = "default"
                        }
                    },
                    Token = msg.devicetoken
                };
                FirebaseMessaging.DefaultInstance.SendAsync(m).ContinueWith(t => Log("Recieved: " + t.Status.ToString()));

t just has an id and status="Faulted".

I've tried removing the AndroidConfig for ios devices, and I've tried adding an ApsAlert to the Aps, but the result is always the same. I've even tried recreated the service account key, using an apn cert instead of a key, and generating a new apns key. No change for all 3, separately.

What can I do to find out what Faulted means, and what's changed to have APNs stop working but Android push keep working?

google-oss-bot commented 3 years ago

I found a few problems with this issue:

hiranya911 commented 3 years ago

I'd say start by looking at t.Exception. If the task faulted, you should be able to get hold of the underling exception this way.

If it looks like a problem with the FCM service, please reach out to Firebase Support and provide details of your project: https://firebase.google.com/support

chrwei commented 3 years ago

it certainly could be more clear in the docs than an exception doesn't throw.

looks like all the iOS tokens are coming back unregistered.

hiranya911 commented 3 years ago

Task continuations in C# don't throw. So you must check task.Status and task.Exception. You should use await for conventional exception throw.

try
{
  await FirebaseMessaging.DefaultInstance.SendAsync(m);
}
catch (FirebaseMessagingException e)
{
  if (e.MessagingErrorCode == MessagingErrorCode.Unregistered)
  {
    Console.WriteLine("Token unregistered");
  }
}