On open event not triggered when opening a notification
Hello,
I set up the SDK and it's working, I can receive notification from my Batch account.
But I have trouble listening to the 'onOpen' event. I am using 'react-native-push-notification' to handle the events and it's working for the 'onReceive' one but nothing when I open the notification.
Example code:
import React, { useEffect, useState } from 'react';
import {
View,
Text,
} from 'react-native';
import NotifService from './NotificationService';
import { Batch } from '@bam.tech/react-native-batch';
const App = () => {
const [init, setInit] = useState(false);
const [notif, setNotif] = useState(undefined);
const onNotification = notification => {
console.log('notif', notification);
// Do something when notification.foreground is false
};
const initApp = async () => {
setNotif(
new NotifService(onNotification, 'sender_id')
);
Batch.start();
setInit(true);
};
useEffect(() => {
if (!init && notif === undefined) {
initApp();
}
}, [init, notif, loading]);
return (
<View>
<Text>Hello</Text>
</View>
);
};
export default App;
And here is my NotificationService:
import PushNotification from 'react-native-push-notification';
export default class NotifService {
constructor(,onNotification, gmc) {
this.configure(onNotification, gmc);
}
configure(onNotification, gcm) {
PushNotification.configure({
onNotification,
senderID: gcm,
});
}
checkPermission(cbk) {
return PushNotification.checkPermissions(cbk);
}
cancelNotif(id) {
PushNotification.cancelLocalNotifications({ id });
}
cancelAll() {
PushNotification.cancelAllLocalNotifications();
}
}
My onNotification function is called when I receive a notification, but not when I open it.
(If I send a notification using FCM, it works fine).
Can you help me with that? Do you need more info about my setup?
Thank you
Hello,
the react-native-batch-push module does not deal with open events or events listeners in general. Your problem likely lies with your Batch iOS integration or the Batch iOS SDK, make sure to have an up-to-date version of the SDK and see the UNUserNotificationCenterDelegate note.