fcm
fcm copied to clipboard
Can't delete instance after first performed
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
- toggle = true; - works and updates database as expected.
- toggle = false; - works and deleteInstance() is fired without error , however messaging occurs
- toggle = true; works and updates database as expected.
- 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});
}
it's not a show stopper as I can use the value "fcmToken" in the database which is null when toggled off