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) => {
/* @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;
constructor(props) {
super(props);
switch (Platform.OS) {
case 'ios':
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());
});
constructor(props) {
super(props);
switch (Platform.OS) {
case 'ios':
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());
listen(name: string, handler: (...empty) => void | Promise) {
if (Platform.OS === 'ios') {
NotificationsIOS.addEventListener(name, handler);
this.unsubs.push(() => NotificationsIOS.removeEventListener(name, handler));
}
const subscription = DeviceEventEmitter.addListener(name, handler);
this.unsubs.push(() => subscription.remove());
}
constructor() {
this.onRegister = null;
this.onNotification = null;
this.deviceToken = null;
NotificationsIOS.addEventListener('remoteNotificationsRegistered', (deviceToken) => {
this.deviceToken = deviceToken;
});
NotificationsIOS.addEventListener('notificationOpened', (notification, completion) => {
const { background } = reduxStore.getState().app;
if (background) {
this.onNotification(notification);
}
completion();
});
const actions = [];
actions.push(new NotificationCategory({
identifier: 'MESSAGE',
actions: [replyAction]
}));
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;
}
Router.SingleIssue({issueId: ytIssueId});
});
export function registerForPush(api: Api): Promise {
return new Promise(async (resolve, reject) => {
/**
constructor() {
this.deviceNotification = null;
this.onRegister = null;
this.onNotification = null;
this.onReply = null;
this.reduxStore = null;
NotificationsIOS.addEventListener(DEVICE_REMOTE_NOTIFICATIONS_REGISTERED_EVENT, this.onRemoteNotificationsRegistered);
NotificationsIOS.addEventListener(DEVICE_NOTIFICATION_RECEIVED_FOREGROUND_EVENT, this.onNotificationReceivedForeground);
NotificationsIOS.addEventListener(DEVICE_NOTIFICATION_OPENED_EVENT, this.onNotificationOpened);
}