Struggling for several weeks to get Push Notifications working on a 10.18.1 PWA Mendix App on mobile devices. (Inbetween I got maybe lucky with 1-3 out of over 20 messages, but currently none or "This site has been updated in the background."-message) I tried Pusher module, but didn't understand what to do (creating a pusher app and defining an object to send or retrieve, but that did not work). I tried Firebase with the Push Notifications Connector Module (https://docs.mendix.com/refguide/mobile/using-mobile-capabilities/push-notifications/), but when I want to register my Firebase App (with Id and private key file) I get errors like: Encryption Module Error while encrypting string: Key should not be empty But the firebase values I inputted get sent to this point according to the debugger. Then I tried manually by setting up firebase app registration in the index.html, registering a service worker like this: index.html if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/firebase-messaging-sw.js') .then((registration) => { registration.update() Notification.requestPermission().then((permission) => { if (permission === 'granted') { getToken(messaging, { vapidKey: '...', serviceWorkerRegistration: registration }).then((currentToken) => { if (currentToken) { console.log('FCM Token:', currentToken); alert(currentToken) // save token } }) const options = { title: 'test', message: 'This is Message Body', }; try { // test foreground message without connection is displayed on Android registration.showNotification('This is Message Title', options); } catch (error) { console.log(error) } } else { // warn } }); }); firebase-messaging-sw.js importScripts("https://www.gstatic.com/firebasejs/11.4.0/firebase-app-compat.js"); importScripts("https://www.gstatic.com/firebasejs/11.4.0/firebase-messaging-compat.js"); firebase.initializeApp({ apiKey: "...", authDomain: "...", projectId: "...", storageBucket: "...", messagingSenderId: "...", appId: "..." }); const messaging = firebase.messaging(); messaging.onBackgroundMessage(function (payload) { console.log('[firebase-messaging-sw.js] Hintergrundnachricht erhalten: ', payload); notificationTitle = payload.notification?.title || payload.data?.title || "Keine Überschrift"; notificationOptions = { body: payload.notification?.body || payload.data?.body || "Keine Nachricht" // icon: '/icons/icon-192x192.png' }; self.registration.showNotification(notificationTitle, notificationOptions); }); self.addEventListener("push", function (e) { const dataObj = e.data.json(); const notificationData = dataObj.notification; const notificationTitle = notificationData.title; const notificationOptions = { body: notificationData.body, icon: notificationData.image, }; //Do some logic to fulfill the notificationOptions e.waitUntil( self.registration.showNotification(notificationTitle, notificationOptions) ); }); I send the messages with the firebase console messaging site or the Java firebase admin sdk functionality. The sending and receiving works on Windows browsers with no problem. So I'm currently stuck and don't know what to check next, I can only try to find out what the Encryption error is about. My registration token retrieval is also not optimal with localStorage access (my Nanoflows or widgets did not work out). Edit: Okay after configuring the Encryption key locally/Environment variables the registering in Push Notifications Module works, but not the sending of the Push messages, they are still in pending state in the messages tab on the server. Probably there is a problem about the Scheduled_Event sending the messages, in MxStudio locally I have some error messages on Startup: Microflow 'PushNotifications.SE_Message_Cleanup' could not be found Microflow 'PushNotifications.FlushMessageQueue' could not be found Do you have any idea what to check or edit in the Push Notification process? Hope to hear from you!
asked
Manuel Gentes
2 answers
1
I didn't look into the rest, but did you set up an encryption key in the encryption module? That should solve this error:
Encryption Module
Error while encrypting string: Key should not be empty
answered
Eline Bijkerk
0
Hi Manuel,
Please check out this article for pwa push notifications