Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning CS0618: 'FirebaseInstanceIdService' is obsolete: 'This class is obsoleted in this android platform

I get the following warnings if I use the code provided in the tutorial:

Warning CS0618: 'FirebaseInstanceIdService' is obsolete: 'This class is obsoleted in this android platform'

Warning CS0672: Member 'MyFirebaseIIDService.OnTokenRefresh()' overrides obsolete member 'FirebaseInstanceIdService.OnTokenRefresh()'. Add the Obsolete attribute to 'MyFirebaseIIDService.OnTokenRefresh()'.

Warning CS0618: 'FirebaseInstanceId.Token' is obsolete: 'deprecated'

I don't understand if I can use this code like it is right now or if it is necessary to change something in order that the code will work on current Android devices.

Is it necessary to change the code?

My AndroidManifest.xml settings: Minimum Android version = Android 5.0 (API level 21), Target Android version = Android 9.0 (API level 28)

MyFirebaseIIDService.cs:

using System;
using Android.App;
using Firebase.Iid;
using Android.Util;

namespace Androidproject
{
[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.
    }
}
}

You can find the code sample in this tutorial: https://docs.microsoft.com/en-us/xamarin/android/data-cloud/google-messaging/remote-notifications-with-fcm?tabs=windows

like image 660
Hobbit7 Avatar asked Jul 19 '19 14:07

Hobbit7


1 Answers

When you update to Xamarin.Firebase.Messaging version 71.1740.0 then you start to get compiler warnings about deprecated methods due to changes in the Google libraries. You no longer need FirebaseInstanceIdService so go ahead and remove that. Now you get the device token from your FirebaseMessagingService.OnNewToken method.

like image 114
Trevor Balcom Avatar answered Oct 04 '22 13:10

Trevor Balcom