I've stumbled onto a problem with my Ionic, Angular, and Firebase app.
I've had this problem before, but it seemed to work itself out, and now I'm having it again, and I'm wondering if anyone knows why.
I'm using Firebase FCM to store a user's token
to then send them a notification. On android this works perfectly, and on iOS it used to work..
I generated my GoogleService-Info.plist
file from Firebase and put it in my main folder.
I have the following code to get the fcm
token:
getFCMToken() {
let token;
this.firebaseNative.getToken().then((tok) => {
token = tok;
if(this.platform.is('ios')) {
this.firebaseNative.grantPermission().then((tok) => {
return this.fcmToFirestore(token);
}).catch(error => this.showToast("There was an error: " + error));
} else {
return this.fcmToFirestore(token);
}
}).catch(error => {
this.showToast("There was an error: " + error)
});
}
fcmToFirestore(token) {
if (!token) return;
const devicesRef = this.afs.collection('devices')
const docData = {
token,
userId: this.userData.uid,
}
return devicesRef.doc(token).set(docData);
}
When I run the following code on an iPhone I get the toast message:
There was an error: Firebase isn't initialised
I initialize the app in app.module.ts
in the imports
, which has always worked, and as I said, works fine on android.
Any idea why this doesn't work on iOS? Thanks!
This is an issue with the installed version of firebase plugin.
I mitigated this error by downgrading to 1.0.5
cordova plugin remove cordova-plugin-firebase
cordova plugin add cordova-plugin-firebase@1.0.5 --save
P.S. Make sure config.xml
has firebase mentioned with the required version. This helps to keep versions same across all the development systems.
<plugin name="cordova-plugin-firebase" spec="~1.0.5" />