diff --git a/Examples/simple-fcm-client/app/App.js b/Examples/simple-fcm-client/app/App.js index e95f2c04a8c3eef840182f6742e48ef04e9c930c..48554b7b6546460ece923e6f032df96216a3007f 100644 --- a/Examples/simple-fcm-client/app/App.js +++ b/Examples/simple-fcm-client/app/App.js @@ -65,6 +65,69 @@ export default class App extends Component { }); } + sendRemoteNotification(token) { + let body; + + if(Platform.OS === 'android'){ + body = { + "to": token, + "data":{ + "custom_notification": { + "title": "Simple FCM Client", + "body": "This is a notification with only NOTIFICATION.", + "sound": "default", + "priority": "high", + "show_in_foreground": true + } + }, + "priority": 10 + } + } else { + body = { + "to": token, + "notification":{ + "title": "Simple FCM Client", + "body": "This is a notification with only NOTIFICATION.", + "sound": "default" + }, + "priority": 10 + } + } + + firebaseClient.send(JSON.stringify(body), "notification"); + } + + sendRemoteData(token) { + let body = { + "to": token, + "data":{ + "title": "Simple FCM Client", + "body": "This is a notification with only DATA.", + "sound": "default" + }, + "priority": "normal" + } + + firebaseClient.send(JSON.stringify(body), "data"); + } + + sendRemoteNotificationWithData(token) { + let body = { + "to": token, + "notification":{ + "title": "Simple FCM Client", + "body": "This is a notification with NOTIFICATION and DATA (NOTIF).", + "sound": "default" + }, + "data":{ + "hello": "there" + }, + "priority": "high" + } + + firebaseClient.send(JSON.stringify(body), "notification-data"); + } + render() { let { token, tokenCopyFeedback } = this.state; @@ -94,16 +157,16 @@ export default class App extends Component { Remote notif won't be available to iOS emulators - firebaseClient.sendNotification(token)} style={styles.button}> - Send Notification + firebaseClient.sendRemoteNotification(token)} style={styles.button}> + Send Remote Notification - firebaseClient.sendData(token)} style={styles.button}> - Send Data + firebaseClient.sendRemoteData(token)} style={styles.button}> + Send Remote Data - firebaseClient.sendNotificationWithData(token)} style={styles.button}> - Send Notification With Data + firebaseClient.sendRemoteNotificationWithData(token)} style={styles.button}> + Send Remote Notification With Data this.showLocalNotification()} style={styles.button}> diff --git a/Examples/simple-fcm-client/app/FirebaseClient.js b/Examples/simple-fcm-client/app/FirebaseClient.js index f537a4e68c12e25ac642a5a2ac55b195eae3cce2..18c27715fbdd1c268b2db07293dfae38f7496322 100644 --- a/Examples/simple-fcm-client/app/FirebaseClient.js +++ b/Examples/simple-fcm-client/app/FirebaseClient.js @@ -11,70 +11,7 @@ class FirebaseClient { this.sendNotificationWithData = this.sendNotificationWithData.bind(this); } - sendNotification(token) { - let body; - - if(Platform.OS === 'android'){ - body = { - "to": token, - "data":{ - "custom_notification": { - "title": "Simple FCM Client", - "body": "This is a notification with only NOTIFICATION.", - "sound": "default", - "priority": "high", - "show_in_foreground": true - } - }, - "priority": 10 - } - } else { - body = { - "to": token, - "notification":{ - "title": "Simple FCM Client", - "body": "This is a notification with only NOTIFICATION.", - "sound": "default" - }, - "priority": 10 - } - } - - this._send(JSON.stringify(body), "notification"); - } - - sendData(token) { - let body = { - "to": token, - "data":{ - "title": "Simple FCM Client", - "body": "This is a notification with only DATA.", - "sound": "default" - }, - "priority": "normal" - } - - this._send(JSON.stringify(body), "data"); - } - - sendNotificationWithData(token) { - let body = { - "to": token, - "notification":{ - "title": "Simple FCM Client", - "body": "This is a notification with NOTIFICATION and DATA (NOTIF).", - "sound": "default" - }, - "data":{ - "hello": "there" - }, - "priority": "high" - } - - this._send(JSON.stringify(body), "notification-data"); - } - - async _send(body, type) { + async send(body, type) { if(FirebaseClient.KEY === 'YOUR_API_KEY'){ Alert.alert('Set your API_KEY in app/FirebaseConstants.js') return;