Created
May 23, 2017 17:28
-
-
Save ShaileshPrajapati-BTC/29326770cff28cee2cb01958fd79b5fe 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
import React, { Component } from "react"; | |
import FCM from "react-native-fcm"; | |
export default class PushNotification extends Component { | |
constructor(props) { | |
super(props); | |
} | |
componentDidMount() { | |
FCM.requestPermissions(); | |
FCM.getFCMToken().then(token => { | |
console.log("TOKEN (getFCMToken)", token); | |
}); | |
FCM.getInitialNotification().then(notif => { | |
console.log("INITIAL NOTIFICATION", notif) | |
}); | |
this.notificationUnsubscribe = FCM.on("notification", notif => { | |
console.log("a", notif); | |
if (notif && notif.local_notification) { | |
return; | |
} | |
this.sendRemote(notif); | |
}); | |
this.refreshUnsubscribe = FCM.on("refreshToken", token => { | |
console.log("TOKEN (refreshUnsubscribe)", token); | |
this.props.onChangeToken(token); | |
}); | |
} | |
sendRemote(notif) { | |
console.log('send'); | |
FCM.presentLocalNotification({ | |
title: notif.title, | |
body: notif.body, | |
priority: "high", | |
click_action: notif.click_action, | |
show_in_foreground: true, | |
local: true | |
}); | |
} | |
componentWillUnmount() { | |
this.refreshUnsubscribe(); | |
this.notificationUnsubscribe(); | |
} | |
render() { | |
return null; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Got a warning error when i used this in my code "invalid FCM Event subscription".