Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
NotificationsIOS.addEventListener('notificationReceivedForeground', notification => {
this.onNotificationReceivedForeground(notification.getData());
});
NotificationsIOS.addEventListener('notificationReceivedBackground', notification => {
this.onNotificationReceivedBackground(notification.getData());
});
NotificationsIOS.addEventListener('notificationOpened', notification => {
this.onNotificationOpened(notification.getData());
});
break;
case 'android':
if (!LISTENERS_ADDED) {
LISTENERS_ADDED = true;
NotificationsAndroid.setRegistrationTokenUpdateListener(async deviceToken => {
// console.log('PUSHLOG: setRegistrationTokenUpdateListener', deviceToken);
// TODO: Send the token to my server so it could send back push notifications...
const tokenSucceeded = await client.mutate({
mutation: ADD_TOKEN,
variables: {
token: deviceToken,
os: 'android',
},
});
if (tokenSucceeded) {
await AsyncStorage.setItem('push-token', deviceToken);
}
});
NotificationsAndroid.refreshToken();
// On Android, we allow for only one (global) listener per each event type.
constructor() {
this.onRegister = null;
this.onNotification = null;
this.deviceToken = null;
NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => {
this.deviceToken = deviceToken;
});
NotificationsAndroid.setNotificationOpenedListener((notification) => {
this.onNotification(notification);
});
}
export const initializeNotifications = (auth: Auth, saveTokenPush: SavePushTokenCallback) => {
NotificationsAndroid.setRegistrationTokenUpdateListener(async deviceToken => {
try {
const result = await registerPush(auth, deviceToken);
saveTokenPush(deviceToken, result.msg, result.result);
} catch (e) {
logErrorRemotely(e, 'failed to register GCM');
}
});
};
constructor() {
this.onRegister = null;
this.onNotification = null;
this.onReply = null;
this.deviceNotification = null;
this.deviceToken = null;
NotificationsAndroid.setRegistrationTokenUpdateListener((deviceToken) => {
this.deviceToken = deviceToken;
if (this.onRegister) {
this.onRegister({token: this.deviceToken});
}
});
NotificationsAndroid.setNotificationReceivedListener((notification) => {
if (notification) {
const data = notification.getData();
this.handleNotification(data, false);
}
});
NotificationsAndroid.setNotificationOpenedListener((notification) => {
if (notification) {
const data = notification.getData();