Created
October 8, 2016 14:01
-
-
Save npomfret/2566cc84ada1a807d201b8146e1fa25e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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, | |
}); | |
} | |
} |
why do we need popInitial method?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
sir,now working fine.......... problem was incorrect way of send notification when i aded more details in message i got it working