Skip to content

Instantly share code, notes, and snippets.

@leenasn
Last active October 11, 2017 10:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save leenasn/7ec4f47851a440582a9ef44b26ead426 to your computer and use it in GitHub Desktop.
Save leenasn/7ec4f47851a440582a9ef44b26ead426 to your computer and use it in GitHub Desktop.
Push notification configure
import PushNotification from 'react-native-push-notification'
//App.js
async componentDidMount(){
PushNotification.configure({
popInitialNotification: true,
requestPermissions: true,
// (required) Called when a remote or local notification is opened or received
onNotification(notification) {
console.log('NOTIFICATION:', notification)
},
// IOS ONLY (optional): default: all - Permissions to register.
permissions: {
alert: true,
badge: true,
sound: true,
},
})
}
//notification.js
export const handleNotificationSelection = notification => {
const { path } = notification.data || notification.userInfo
// console.log(path, 'path')
if (path) {
emitDeepLinkURL(path)
}
}
//GlobalMeditationJoin.js
schedule = (selectedGlobalMeditation, dispatch) => {
const { id, scheduled_at } = selectedGlobalMeditation
//let notificationDate = new Date(Date.now() + 60000)
let notificationDate = new Date(new Date(scheduled_at) - 5 * 60000)
let notificationMessage = I18n.t('globalMeditation.notificationMessage')
PushNotification.localNotificationSchedule({
message: notificationMessage, // (required)
date: notificationDate, // in 60 secs
// to pass data
userInfo: {
path: 'meditation/globalMeditation',
},
})
console.log('scheduled notifiation for ', notificationDate)
dispatch(joinGlobalMeditation(id))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment