From 98939636f693c6869cbaef2ae84e5e6b52441808 Mon Sep 17 00:00:00 2001 From: Libin Lu Date: Thu, 9 Nov 2017 11:16:23 -0500 Subject: [PATCH] move functions --- Examples/simple-fcm-client/app/App.js | 75 +++++++++++++++++-- .../simple-fcm-client/app/FirebaseClient.js | 65 +--------------- 2 files changed, 70 insertions(+), 70 deletions(-) diff --git a/Examples/simple-fcm-client/app/App.js b/Examples/simple-fcm-client/app/App.js index e95f2c0..48554b7 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 f537a4e..18c2771 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; -- 2.26.2