diff --git a/Examples/simple-fcm-client/app/App.js b/Examples/simple-fcm-client/app/App.js index a358221772de07feb0393837b8aae621b45f03f2..a23d555849d0fdf743c69917e9dd0e5bde4dd9fd 100644 --- a/Examples/simple-fcm-client/app/App.js +++ b/Examples/simple-fcm-client/app/App.js @@ -16,19 +16,35 @@ import PushController from "./PushController"; import firebaseClient from "./FirebaseClient"; export default class App extends Component { + constructor(props) { + super(props); + + this.state = { + token: "" + } + } + render() { + let { token } = this.state; + return ( - + this.setState({token: token || ""})} + /> Welcome to Simple Fcm Client! - firebaseClient.sendNotification()} style={styles.button}> + + Token: {this.state.token} + + + firebaseClient.sendNotification(token)} style={styles.button}> Send Notification - firebaseClient.sendData()} style={styles.button}> + firebaseClient.sendData(token)} style={styles.button}> Send Data diff --git a/Examples/simple-fcm-client/app/FirebaseClient.js b/Examples/simple-fcm-client/app/FirebaseClient.js index f6bb1bdf42c10193d30cc43fb1523dc7120da57d..1f13297a5b2c8fe7eeada0733dc22d322fac6015 100644 --- a/Examples/simple-fcm-client/app/FirebaseClient.js +++ b/Examples/simple-fcm-client/app/FirebaseClient.js @@ -4,9 +4,14 @@ const API_URL = "https://fcm.googleapis.com/fcm/send"; class FirebaseClient { - sendNotification() { + constructor() { + this.sendData = this.sendData.bind(this); + this.sendNotification = this.sendNotification.bind(this); + } + + sendNotification(token) { let body = { - "to": FirebaseConstants.TO, + "to": token, "notification":{ "icon": "appLogo", "title": "Notification Title", @@ -14,15 +19,16 @@ class FirebaseClient { "sound": "default", "click_action": "fcm.ACTION.HELLO" }, + "content_available": true, "priority": 10 } this._send(JSON.stringify(body), "notification"); } - sendData() { + sendData(token) { let body = { - "to": FirebaseConstants.TO, + "to": token, "data":{ "icon": "appLogo", "title": "Notification Title", @@ -30,6 +36,7 @@ class FirebaseClient { "sound": "default", "click_action": "fcm.ACTION.HELLO" }, + "content_available": true, "priority": 10 } diff --git a/Examples/simple-fcm-client/app/PushController.js b/Examples/simple-fcm-client/app/PushController.js index 5fa9c53d9710653ce5e780098856795de009e121..c6ca152a0f6626d6cadb084f35963bddd8ad448a 100644 --- a/Examples/simple-fcm-client/app/PushController.js +++ b/Examples/simple-fcm-client/app/PushController.js @@ -2,12 +2,19 @@ import React, { Component } from "react"; import FCM from "react-native-fcm"; +import firebaseClient from "./FirebaseClient"; + export default class PushController extends Component { + constructor(props) { + super(props); + } + componentDidMount() { FCM.requestPermissions(); FCM.getFCMToken().then(token => { console.log("TOKEN (getFCMToken)", token); + this.props.onChangeToken(token); }); FCM.getInitialNotification().then(notif => { @@ -20,6 +27,7 @@ export default class PushController extends Component { this.refreshUnsubscribe = FCM.on("refreshToken", token => { console.log("TOKEN (refreshUnsubscribe)", token); + this.props.onChangeToken(token); }); }