覆盖 Firebase 应用的 DefaultInstance。重新初始化:java.lang.IllegalStateException:FirebaseApp 被删除
Posted
技术标签:
【中文标题】覆盖 Firebase 应用的 DefaultInstance。重新初始化:java.lang.IllegalStateException:FirebaseApp 被删除【英文标题】:Overwrite DefaultInstance of the firebase app. Re-initialize: java.lang.IllegalStateException: FirebaseApp was deleted 【发布时间】:2022-01-08 19:29:13 【问题描述】:我想在初始化后更改 FirebaseApp 配置,但出现错误 - “java.lang.IllegalStateException: FirebaseApp was deleted”
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);
如何解决?
【问题讨论】:
【参考方案1】:修复 - 已删除令牌和我们 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
【讨论】:
以上是关于覆盖 Firebase 应用的 DefaultInstance。重新初始化:java.lang.IllegalStateException:FirebaseApp 被删除的主要内容,如果未能解决你的问题,请参考以下文章
插入 Firebase 实时数据库会覆盖数据而不是追加,如何让它追加而不是在 js 中覆盖?