Last active
October 11, 2017 10:11
-
-
Save leenasn/7ec4f47851a440582a9ef44b26ead426 to your computer and use it in GitHub Desktop.
Push notification configure
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
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