Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
initalizePushNotifications() {
UrbanAirship.setUserNotificationsEnabled(true)
UrbanAirship.addListener("register", (event) => {
console.log('Channel registration updated: ', event.channelId);
console.log('Registration token: ', event.registrationToken);
});
UrbanAirship.addListener("pushReceived", (notification) => {
console.log('Received push: ', JSON.stringify(notification));
});
UrbanAirship.setForegroundPresentationOptions({
alert: true,
sound: true,
badge: true
});
}
async initializePushNotifications() {
const { navigation } = this.props
UrbanAirship.getChannelId().then(channelId => {
if (channelId) {
this.props.registerChannelID(channelId, Platform.OS)
}
})
const { notificationsEnabled } = this.props.state
UrbanAirship.setUserNotificationsEnabled(notificationsEnabled)
UrbanAirship.addListener("pushReceived", async(notification) => {
const actions = JSON.parse(notification.extras['com.urbanairship.actions'])
const { type } = actions
if(type === 'NewPendingCredit') {
loadingPending.wrap(this.props.getPending())
} else if(type === 'NewFriendRequest') {
loadingFriends.wrap(this.props.getFriends())
} else if(type === 'RequestPayPal') {
loadingPayPalRequests.wrap(this.props.getPayPalRequests())
}
})
UrbanAirship.addListener("notificationResponse", async(incoming) => {
try{
const actions = JSON.parse(incoming.notification.extras['com.urbanairship.actions'])
const { type, user } = actions
handleNotificationsEnabled(enabled) {
UrbanAirship.setUserNotificationsEnabled(enabled)
this.setState({notificationsEnabled:enabled});
}
handleNotificationsEnabled(enabled) {
UrbanAirship.setUserNotificationsEnabled(enabled)
this.setState({notificationsEnabled:enabled});
}
return async (dispatch, getState) => {
const oldSetting = getState().store.notificationsEnabled
const notificationsEnabled = !oldSetting
await notificationsEnabledStorage.set(notificationsEnabled)
await UrbanAirship.setUserNotificationsEnabled(notificationsEnabled)
dispatch(setState({ notificationsEnabled }))
}
}