Created
October 8, 2016 14:01
-
-
Save npomfret/2566cc84ada1a807d201b8146e1fa25e to your computer and use it in GitHub Desktop.
This file contains hidden or 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, | |
}); | |
} | |
} |
sir,now working fine.......... problem was incorrect way of send notification when i aded more details in message i got it working
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
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, thanks for this code ..........................by importing this file now i am able to receive notification received message even when the app is closed(i got notification received message in react-native android-log) but in app its not showing any notification how to correct this? All i did was pasted this code in notifications .js file and imported it to app.js file
import {PushNotifications} from './notification.js';