Hi,
I have been trying to implement FCM in my Ionic 2 app. I have added the firebase plugin from ionic native, and the integration appears to be working nicely on my android phone. I can receive the data of the push-notifications when my app is in background mode, since the display of notfications is handled automatically in that case. However, when the app is in foreground mode I am not sure how to actually retrieve the notification data in the callback. I receive an object from firebase with a tap property that is true if the app is in background mode and false if in foreground mode. It is not clear to me from expecting the object in the console where to retrieve the data from, or if it is even there. I have tried doing res.data and JSON.stringify on res (only contains the tap property), but to no avail. Here’s my code:
import { Firebase } from 'ionic-native';
Firebase.getToken()
.then(token => console.log(`The token is ${token}`)) // save the token server-side and use it to push notifications to this device
.catch(error => console.error('Error getting token', error));
Firebase.onTokenRefresh()
.subscribe((token: string) => console.log(`Got a new token ${token}`));
Firebase.onNotificationOpen()
.subscribe(res => {
if(res.tap) {
// background mode
console.log("background");
console.log(res);
} else if (!res.tap) {
// foreground mode
console.log("foreground");
console.log(res);
}
});
Any clues on how to get the data in the onNotificationOpen callback? Or should be fetched in another way? Since the ionic2 implementation is using observables I cannot turn to the actual github documentation of the project.