簡體   English   中英

Flutter Firebase push onLaunch 在應用程序刷新時調用多次

[英]Flutter Firebase push onLaunch called multiple times on app refresh

每當我刷新應用程序時,我都會面臨多次調用onLaunch方法的問題。

在這里找到了 git 問題

您可以刪除 Firebase 應用程序並重新請求權限。

在下面的示例中,我會將用戶傳遞給 on Launch:

onLaunch(User user) async {
  Firebase.initializeApp().then((value) async {
    try {
      value.delete(); // The default Firebase app instance cannot be deleted. but this will remove previous subscriptions.
    } catch (e) {}
    FirebaseMessaging messaging = FirebaseMessaging.instance;
    NotificationSettings settings = await messaging.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    String token = await messaging.getToken(); // get the token
    user.mobileId = token.toString();
    BackendRequester.registerPushClient(user); // send it to the backend

    messaging.onTokenRefresh.listen((token) { // if token refreshed will notify the backend
      user.mobileId = token.toString();
      BackendRequester.registerPushClient(user);
    });
  });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM