0

I was able to receive push notifications some months ago, a day ago i started to work again on the app now the issue is it's not able to receive push notification. It does provide FCM token but onMessageReceived never gets called also if i try with Postman it gives an error of Mismatchsender ID, but the scenario here is a bit confusing. If i change the package name (after creating new project on console and added new goole-service.json file) it doesn't let me register for FCM token. i've stuck in this situation from last day. can anybody please help? what i'm doing wrong.

Here is implementaion of FCMToken

 [Service]
    [IntentFilter(new[] { "com.google.firebase.INSTANCE_ID_EVENT" })]
    public class MyFirebaseIIDService : FirebaseInstanceIdService
    {
        const string TAG = "MyFirebaseIIDService";
        public override void OnTokenRefresh()
        {
            var refreshedToken = FirebaseInstanceId.Instance.Token;
            Log.Debug(TAG, "Refreshed token: " + refreshedToken);
            SendRegistrationToServer(refreshedToken);
        }
        void SendRegistrationToServer(string token)
        {
            // Add custom implementation, as needed.
        }
    }

Here it gives me error if i change my package name to any other,

Error: Java.Lang.IllegalStateException: Default FirebaseApp is not initialized in this process

try
            {
                var refreshedToken = FirebaseInstanceId.Instance.Token;
              //  PushNotificationManager.Initialize(this, false);
            } catch(Exception ee)
            {

            }

  • FYI `FirebaseInstanceIdService` is deprecated. You should update the code using the following: https://stackoverflow.com/questions/51148336/what-to-do-with-the-instance-id-event-action-with-firebase-17-0-1 – CodingLumis Apr 02 '20 at 17:05
  • Thanks for your kind suggestion. i had updated the same & now it's perfectly fine. – Muhammad Adeel Shoukat Apr 03 '20 at 04:57

1 Answers1

0

I've solved my issue with with customization of FirebaseInitialize after creating new project on Firebase here is my code. But one bad thing is here that when new token gets initialized it never gets called on FirebaseInstanceIdReceiver.

var options = new FirebaseOptions.Builder()
  .SetApplicationId("<AppID>")
  .SetApiKey("<ApiKey>")
  .SetDatabaseUrl("<DBURl>")
  .SetStorageBucket("<StorageBucket>")
  .SetGcmSenderId("<SenderID>").Build();
  var fapp = FirebaseApp.InitializeApp(this, options);