Hi there!
In the Ionic docs, the FCM plugin page has some quick example on how to make it work. Well, I managed to install the Cordova plugin and actually got notifications showing up in my phone (yay!), but there are two things that are messed up that don’t seem to work.
- I can’t get any token from .getToken() or .onTokenRefresh(). They just don’t ever return anything.
- When I click in a notification sent from the Firebase Console or the online notification tester they have, I see the notification, but when I click on it, my handlers do not work.
My implementation is this one:
@Injectable({
providedIn: 'root'
})
export class PushHandlerService {
constructor(
private fcm: FCM,
private platform: Platform
) {
}
initialize() {
try {
this.platform.ready().then(() => {
console.log("Inicializando pushhandler")
const user = Parse.User.current();
this.fcm.onTokenRefresh().subscribe(token => {
console.log("token received: ", token)
user.set("FCMToken", token)
user.save()
.then(() => console.log("[PushHandler] Token saved in Parse's User"))
.catch(err => console.log("[PushHandler] Error saving FCM token"));
});
this.setHandlers();
});
} catch(err) {
console.log("[PushHandler] ERROR: ", err)
}
}
setHandlers() {
console.log("Setting up handlers")
try {
// Subscribe to schedule reminders
// this.fcm.subscribeToTopic('scheduleReminders');
this.fcm.onNotification().subscribe(data => {
console.log("RECEIVED MESSAGE")
if (data.wasTapped) {
// User tapped in the push notification
console.log("User tapped, data", data)
alert(data);
} else {
// User did not tap; is it needed to notify him anyways?
console.log("User did not tap, data", data)
alert(data)
}
});
console.log("[PushNotification] Handlers set up");
} catch (err) {
console.log("[PushHandler] ERROR: ", err)
}
}
I also added the FCM plugin to the “providers” part in the main module.
Every other code seems to work, console.logs say so. But these two parts won’t ever work; they don’t even return any kind of message or error. What’s wrong here?