Hi guys,
We have integrated in our application the push notification capacitor firebase plugin and things works fine.
We received notification when app it’s closed, or in background. But we have from time to time a problem, and also it’s not reproducible in any device/phone, the problem appears on ios, we couldn’t replicate the issue in android thus far.
The problem occured in some case: if we left the application in background for a while(for example during the night) and in this time we received a notification, when we open the notification the “pushNotificationActionPerformed” listener it’s not triggered all the times, something like it’s not there. We have the initialization of the notifications listeners in a service. It’s looks like the notification listener it’s not created in some cases when we tap on notification. Do you think that it’s possible that the app to be somehow refreshed and the data from the service, implicitelly the push notifications listeners to be destroyed because we added the listeners in a service, and not in app.component.ts or in other component?
Our service looks like that:
@Injectable({
providedIn: “root”,
})
export class PushNotificationService {
constructor(
private platform: Platform
) {
if (!this.platform.is(“desktop”)) {
this.createPushNotificationListener();
}
}
initPushNotifications() {
this.sharedDataService.pushNotificationListenerCreated();
PushNotifications.requestPermissions().then((result) => {
if (result.receive === “granted”) {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
PushNotifications.addListener("registration", (token: Token) => {
alert("registration");
}
});
PushNotifications.addListener("registrationError", (error: any) => {
alert('Error on registration: ' + JSON.stringify(error));
});
PushNotifications.addListener(
"pushNotificationReceived",
(notification: PushNotificationSchema) => {
// alert('Push received: ' + JSON.stringify(notification));
}
);
}
createPushNotificationListener() {
PushNotifications.removeAllListeners();
// Method called when tapping on a notification
PushNotifications.addListener(
"pushNotificationActionPerformed",
(notification: ActionPerformed) => {
aler("pushNotificationActionPerformed");
} catch (error) {
alert(error);
);
}
}
);
}
}
We call initPushNotification method from ngOnInit from app.component.ts, we also tried to have all the listeners(“pushNotificationActionPerformed” inclusive) in the same method, but we got the same issue, that why we moved that listener in a separate method that it’s called from the constructor of the service.
Any help or suggestion would be very helpful, thank you very much!
1 post - 1 participant