When a push notification arrives while your React Native iOS application is in the foreground, it needs to be handled by a specific event listener. The default behavior, such as showing a system alert or triggering a deep link, often relies on the user tapping the notification, which is handled by a different event.
To correctly process notifications in the foreground and handle taps, you must implement two distinct event listeners:
pushReceived: This event is triggered when the device receives a push notification while your app is running in the foreground. You can use this to perform actions like showing an in-app alert or logging the event.pushOpened: This event is triggered when a user taps on a push notification. This is the appropriate place to implement your deep linking logic.
These listeners should be set up early in your application's lifecycle, typically after initializing the Pushwoosh SDK.
Here is an example of how to set up the listeners:
import { DeviceEventEmitter } from 'react-native';
import Pushwoosh from 'pushwoosh-react-native-plugin';
// Set up the event listeners
DeviceEventEmitter.addListener('pushReceived', (e) => {
console.log("Push received in foreground: " + JSON.stringify(e));
// Add custom logic for handling a foreground notification here
});
DeviceEventEmitter.addListener('pushOpened', (e) => {
console.log("Push opened: " + JSON.stringify(e));
// Add your deep link redirection logic here
});
Troubleshooting
If you are still not seeing logs or the events are not firing as expected, you can enable verbose logging for the Pushwoosh SDK to get more detailed diagnostic information in your console.
To enable verbose logging for iOS, add the Pushwoosh_LOG_LEVEL key to your project's Info.plist file with the string value VERBOSE.
<key>Pushwoosh_LOG_LEVEL</key>
<string>VERBOSE</string>
This will provide detailed logs about the SDK's operations, including registration and notification handling.
Comments
0 comments
Please sign in to leave a comment.