覆盖firebase应用程序的DefaultInstance.重新初始化:java.lang.IollegalState



我想在初始化后更改FirebaseApp的配置,但收到一个错误-"java.lang.IollegalStateException:FirebaseApp已删除";

var apps = FirebaseApp.GetApps(Context);
if (apps.Count != 0 )
{
apps.Where((i) => i.Name == FirebaseApp.DefaultAppName).FirstOrDefault().Delete();
}
var options = new FirebaseOptions.Builder()
.SetApiKey(config["API_KEY"])
.SetApplicationId(config["GOOGLE_APP_ID"])
.SetGcmSenderId(config["GCM_SENDER_ID"])
.SetProjectId(config["PROJECT_ID"])
.SetStorageBucket(config["STORAGE_BUCKET"])
.Build();
FirebaseApp.InitializeApp(Context, options);
if (Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.O)
{
//Change for your default notification channel id here
FirebasePushNotificationManager.DefaultNotificationChannelId = "FirebasePushNotificationChannel";
//Change for your default notification channel name here
FirebasePushNotificationManager.DefaultNotificationChannelName = "General";
FirebasePushNotificationManager.DefaultNotificationChannelImportance = NotificationImportance.Max;
}
FirebasePushNotificationManager.Initialize(Context, false);

如何修复?

修复-已删除令牌和我们Xamarin.Firebase.Messaging而不是PluginFirebasePushNotifications

public async Task<bool> TryDeleteFirebaseAppAsync(string name)
{
var apps = FirebaseApp.GetApps(this);
if (apps.Count != 0)
{
var app = apps.Where((i) => i.Name == name).FirstOrDefault();
await FirebaseMessaging.Instance.DeleteToken();
app.Delete();
return true;
}
else
return false;
}

我的示例:FirebaseTestNotification

最新更新