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('remoteNotificationsRegistered', this.onPushRegistered);
NotificationsIOS.addEventListener(
'remoteNotificationsRegistrationFailed',
this.onPushRegistrationFailed,
);
if (!DeviceInfo.isEmulator()) {
NotificationsIOS.requestPermissions();
}
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',
},
});
// console.log('screen will dim');
// console.log('setting idle timer disabled to false, notifications.ios.js line 43');
IdleTimerManager.setIdleTimerDisabled(false);
}
this.dispatch(updateSilentSwitchState(silent));
}
});
// Push Notifications Configure
OneSignal.addEventListener('ids', this.onIds.bind(this));
OneSignal.addEventListener('received', this.onPushNotificationReceived.bind(this));
OneSignal.configure();
// Local Notifications Configure
NotificationsIOS.addEventListener('notificationReceivedForeground', this.onNotificationReceivedForeground.bind(this));
NotificationsIOS.addEventListener('notificationReceivedBackground', this.onNotificationReceivedBackground.bind(this));
NotificationsIOS.addEventListener('notificationOpened', this.onNotificationOpened.bind(this));
this.snoozeAction = new NotificationAction({
activationMode: 'background',
title: 'Snooze',
identifier: 'SNOOZE_ACTION',
}, (action, completed) => {
this.dispatch(snoozeAlarm(action.notification.getData().alarmUUID));
completed();
});
this.stopAction = new NotificationAction({
activationMode: 'background',
title: 'Stop',
identifier: 'STOP_ACTION',
}, (action, completed) => {
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.
NotificationsAndroid.setNotificationReceivedListener(notification => {
// console.log('PUSHLOG: setNotificationReceivedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationReceivedForeground(notificationData);
});
NotificationsAndroid.setNotificationOpenedListener(notification => {
// console.log('PUSHLOG: setNotificationOpenedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationOpened(notificationData);
});
PendingNotifications.getInitialNotification().then(notifications => {
// console.log('PUSHLOG: getInitialNotification', notifications);
if (notifications) {
notifications.data.forEach(notification => {
const notificationData = JSON.parse(notification.payload);
if (notification.opened) {
this.onNotificationOpened(notificationData);
} else {
this.handlePushData(notificationData);
}
});
}
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.
});
NotificationsAndroid.refreshToken();
// On Android, we allow for only one (global) listener per each event type.
NotificationsAndroid.setNotificationReceivedListener(notification => {
// console.log('PUSHLOG: setNotificationReceivedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationReceivedForeground(notificationData);
});
NotificationsAndroid.setNotificationOpenedListener(notification => {
// console.log('PUSHLOG: setNotificationOpenedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationOpened(notificationData);
});
PendingNotifications.getInitialNotification().then(notifications => {
// console.log('PUSHLOG: getInitialNotification', notifications);
if (notifications) {
notifications.data.forEach(notification => {
const notificationData = JSON.parse(notification.payload);
if (notification.opened) {
this.onNotificationOpened(notificationData);
} else {
this.handlePushData(notificationData);
}
});
}
});
// .catch(err => console.error('getInitialNotifiation() failed', err));
}
break;
default:
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.
NotificationsAndroid.setNotificationReceivedListener(notification => {
// console.log('PUSHLOG: setNotificationReceivedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationReceivedForeground(notificationData);
});
NotificationsAndroid.setNotificationOpenedListener(notification => {
// console.log('PUSHLOG: setNotificationOpenedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationOpened(notificationData);
});
PendingNotifications.getInitialNotification().then(notifications => {
// console.log('PUSHLOG: getInitialNotification', notifications);
if (notifications) {
componentDidMount() {
switch (Platform.OS) {
case 'ios':
// console.log('PUSHLOG: NotificationsIOS.consumeBackgroundQueue();');
NotificationsIOS.consumeBackgroundQueue();
break;
default:
break;
}
}
// 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.
NotificationsAndroid.setNotificationReceivedListener(notification => {
// console.log('PUSHLOG: setNotificationReceivedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationReceivedForeground(notificationData);
});
NotificationsAndroid.setNotificationOpenedListener(notification => {
// console.log('PUSHLOG: setNotificationOpenedListener', notification);
const notificationData = JSON.parse(notification.getData().payload);
this.onNotificationOpened(notificationData);
});
PendingNotifications.getInitialNotification().then(notifications => {
// console.log('PUSHLOG: getInitialNotification', notifications);
if (notifications) {
notifications.data.forEach(notification => {
const notificationData = JSON.parse(notification.payload);
if (notification.opened) {
/* @flow */
import NotificationsIOS from 'react-native-notifications';
import appPackage from '../../../package.json'; // eslint-disable-line import/extensions
import Router from '../router/router';
import log from '../log/log';
import type Api from '../api/api';
const {KONNECTOR_URL} = appPackage.config;
let appleDeviceToken = null;
NotificationsIOS.addEventListener('remoteNotificationsRegistered', deviceToken => {
log.info(`Apple device token received: "${deviceToken}"`);
appleDeviceToken = deviceToken;
});
NotificationsIOS.addEventListener('notificationReceivedBackground', notification => {
log.info('PUSH:notification received in background', notification);
});
NotificationsIOS.addEventListener('notificationReceivedForeground', notification => {
log.info('PUSH:notification received in foreground', notification);
});
NotificationsIOS.addEventListener('notificationOpened', notification => {
const {ytIssueId, ytUserId} = notification.getData();
log.info(`PUSH:notification opened for issue "${ytIssueId}" for user "${ytUserId}"`);
if (!ytIssueId) {
return;
componentWillUnmount() {
switch (Platform.OS) {
case 'ios':
// prevent memory leaks!
NotificationsIOS.removeEventListener(
'remoteNotificationsRegistered',
this.onPushRegistered,
);
NotificationsIOS.removeEventListener(
'remoteNotificationsRegistrationFailed',
this.onPushRegistrationFailed,
);
NotificationsIOS.removeEventListener(
'notificationReceivedForeground',
this.onNotificationReceivedForeground,
);
NotificationsIOS.removeEventListener(
'notificationReceivedBackground',
this.onNotificationReceivedBackground,
);
NotificationsIOS.removeEventListener('notificationOpened', this.onNotificationOpened);
break;
default:
break;
}
}