Pushwoosh.pushReceivedCallback fires whenever a notification is received, including while the app is in the foreground. If it only fires when the app was closed or backgrounded, it is almost always a registration-order or presentation problem rather than a plugin bug.
1. Register the callbacks before onDeviceReady
The plugin stores the callback and keeps it alive; it replays the launch notification and wires up the native notification handlers inside onDeviceReady. Anything registered afterwards can miss events. Register first, initialise second:
import { Pushwoosh } from 'pushwoosh-capacitor-plugin';
Pushwoosh.pushReceivedCallback((notification, err) => {
if (err) { console.error('Failed to receive notification:', err); }
else { console.log('Push Received:', JSON.stringify(notification)); }
});
Pushwoosh.pushOpenedCallback((notification, err) => {
if (err) { console.error('Failed to open notification:', err); }
else { console.log('Push Opened:', JSON.stringify(notification)); }
});
Pushwoosh.onDeviceReady({ appid: 'XXXXX-XXXXX' });
await Pushwoosh.registerDevice();
Call this once, as early as possible in your app bootstrap — not inside a component that mounts later.
2. Make sure onDeviceReady is actually called
If you see the console warning "PUSHWOOSH WARNING: onStart is false, but onDeviceReady has not been called", initialisation never ran and no callbacks will be delivered.
3. iOS: check the AppDelegate
On iOS the plugin swizzles the app delegate's notification handlers during onDeviceReady. If your own AppDelegate implements userNotificationCenter(_:willPresent:withCompletionHandler:) or application(_:didReceiveRemoteNotification:fetchCompletionHandler:) without calling super, the swizzled handler never runs and no foreground callback is delivered. Remove the override or forward to super.
4. Compare against the official example
If it still misbehaves, build and run the example project in the plugin repository at github.com/Pushwoosh/pushwoosh-capacitor-plugin (see the example/ folder). If the callback works there, diff its initialisation order against yours.
Comments
0 comments
Please sign in to leave a comment.