Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't delete instance after first performed #128

Open
jadsy2107 opened this issue Oct 20, 2022 · 1 comment
Open

Can't delete instance after first performed #128

jadsy2107 opened this issue Oct 20, 2022 · 1 comment

Comments

@jadsy2107
Copy link

In my service i have a simple toggle function that to Enable / Disabled notifications with a toggle switch to fire it
It works, creates the token, saves to database and then removes it when toggled again.... the first time only.

steps to reproduce, click toggle 4 times

  1. toggle = true; - works and updates database as expected.
  2. toggle = false; - works and deleteInstance() is fired without error , however messaging occurs
  3. toggle = true; works and updates database as expected.
  4. toggle = false; fails with error

code: "The operation couldn’t be completed. Installation for appID appName __FIRAPP_DEFAULT not found"

errorMessage: "Cant delete Firebase Instance ID"

message: "Cant delete Firebase Instance ID"

  async togglePush(toggle): Promise<boolean> {
    if (toggle) {
      await PushNotifications.requestPermissions();
      await PushNotifications.register();
      const pushPerms = await PushNotifications.checkPermissions();
      if (pushPerms.receive == 'granted') {
        // await FCM.refreshToken();
        await FCM.getToken()
        .then((r) => {
          this.fcmToken = r.token;
        })
        .catch((err) => console.log(err));
        await this.saveFcmToken(this.fcmToken);
        console.log(this.fcmToken);
        return true;
      } else {
        this.fcmToken = null;
        await this.saveFcmToken(null);
        return false;
      }
    } else {
      console.log('deleting instance');
      await FCM.deleteInstance();  ///////////////// THIS THROWS AN ERROR EVERYTIME AFTER INITIAL DELETE 
      this.fcmToken = null;
      await this.saveFcmToken(null);
      return false;
    }
  }

And in my component;

  async togglePush() {
    await this.delay(100);
    this.enableNotifications = await this.userService.togglePush(this.enableNotifications);
  }

the set token function

  async saveFcmToken(fcmToken) {
    const deviceId = await this.getDeviceId();
    const deviceDoc: AngularFirestoreDocument = this.afs.doc(`/devices/${deviceId}`);
    const data = {
      lastUpdated: firestore.serverTimestamp(),
      deviceId: deviceId,
      fcmToken: fcmToken
    }
    await deviceDoc.set(data, {merge: true});
  }
@jadsy2107
Copy link
Author

it's not a show stopper as I can use the value "fcmToken" in the database which is null when toggled off

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant