Skip to content

Instantly share code, notes, and snippets.

@npomfret
Created October 8, 2016 14:01
Show Gist options
  • Save npomfret/2566cc84ada1a807d201b8146e1fa25e to your computer and use it in GitHub Desktop.
Save npomfret/2566cc84ada1a807d201b8146e1fa25e to your computer and use it in GitHub Desktop.
'use strict';
import PushNotification from "react-native-push-notification";
let _pushNotificationToken = null;
const _pushNotificationListeners = [];
function init() {
console.log("PushNotification init");
PushNotification.configure({
onRegister(token) {
console.log('Registered pushNotificationToken:', token);
_pushNotificationToken = token;
},
onNotification(notification) {
console.log("Received pushNotification",);
_pushNotificationListeners.forEach((listener) => {
try {
listener(notification);
} catch (err) {
console.warn("Listener failed to process push notification", err);
}
})
},
senderID: "1068946777489",
permissions: {
alert: true,
badge: true,
sound: true
},
popInitialNotification: false,
requestPermissions: true
});
}
init();
export default class PushNotifications {
constructor() {
}
addListener(listener) {
_pushNotificationListeners.push(listener);
return () => {
this._listeners = this._listeners.filter((l) => l !== listener);
}
}
token() {
return _pushNotificationToken;
}
popInitial() {
PushNotification.configure({
popInitialNotification: true,
});
}
}
@vova-demchuk
Copy link

why do we need popInitial method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment