|
| 1 | +This is a migration guide which can help you switch your app from using push-plugin to using nativescript-plugin-firebase |
| 2 | +1. Go to your app's root folder and execute |
| 3 | +```bash |
| 4 | +tns plugin add nativescript-plugin-firebase |
| 5 | +``` |
| 6 | +> Upon plugin installation, you'll be prompted to choose which features to use. Choose "yes" for Firebase Messaging (of course :)). By default, the plugin saves the configuration as a file (firebase.nativescript.json) to use it when reinstalling the plugin. |
| 7 | +
|
| 8 | +2. Add `GoogleService-Info.plist` (for iOS) or `google-services.json` (for Android) in App_Resources/iOS (and App_Resources/Android, respectively). These are the configuration files that come from your Firebase apps. If you don't have such yet, go to https://console.firebase.google.com and create one. See [firebase plugin's docs]("https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md") for more info on initial setup. |
| 9 | + |
| 10 | +3. Add some code [to handle a notification]("https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md#handling-a-notification") |
| 11 | + |
| 12 | +EXAMPLE: The following code using push-plugin: |
| 13 | +```js |
| 14 | +private pushSettings = { |
| 15 | + notificationCallbackIOS: (message: any) => { |
| 16 | + this.updateMessage("Message received!\n" + JSON.stringify(message)); |
| 17 | + } |
| 18 | +}; |
| 19 | + |
| 20 | +pushPlugin.register(this.pushSettings, (token: String) => { |
| 21 | + console.log("Device registered. Access token: " + token); |
| 22 | + |
| 23 | + pushPlugin.registerUserNotificationSettings(() => { |
| 24 | + console.log("Successfully registered for push."); |
| 25 | + }, (err) => { |
| 26 | + console.log(("Error registering for interactive push: " + JSON.stringify(err)); |
| 27 | + }); |
| 28 | +}, (errorMessage: String) => { |
| 29 | + console.log((JSON.stringify(errorMessage)); |
| 30 | +}); |
| 31 | +``` |
| 32 | +... could be rewriten using firebase like: |
| 33 | +```js |
| 34 | +firebase.init({ |
| 35 | + onMessageReceivedCallback: (message: firebase.Message) => { |
| 36 | + console.log(`Message: ${message}`); |
| 37 | + }, |
| 38 | + onPushTokenReceivedCallback: function(token) { |
| 39 | + console.log("Firebase push token: " + token); |
| 40 | + } |
| 41 | +}); |
| 42 | +``` |
| 43 | +To test with sending messages, you can use the UI in Firebase Console, or use the `https://fcm.googleapis.com/fcm/send` API. See the [testing docs section in firebase plugin]("https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md#testing"). |
| 44 | + |
| 45 | +4. |
| 46 | + |
| 47 | +----------- |
| 48 | + |
| 49 | +2. You can go to demos and see there but below are how some usages of push-plugin translate to firebase: |
| 50 | + |
| 51 | +pushPlugin.areNotificationsEnabled(<some-callback-func>) -> firebase.areNotificationsEnabled(): boolean |
| 52 | +| push-plugin | nativescript-plugin-firebase | |
| 53 | +| :-------------: | :-------------: | |
| 54 | +| pushPlugin.areNotificationsEnabled(<some-callback-func>) | firebase.areNotificationsEnabled(): boolean | |
| 55 | +| |
| 56 | +pushPlugin.register(this.pushSettings) |
| 57 | +pushPlugin.registerUserNotificationSettings() | firebase.registerForInteractivePush(model) | |
0 commit comments