You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 7, 2019. It is now read-only.
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
1
+
# Migration guide push-plugin -> Firebase plugin
2
+
If you have an app that uses push-plugin for push notifications and need to switch to nativescript-plugin-firebase, this guide can help you. If you are just starting with push notifications, however, it would be best to use [Firebase plugin]("https://github.com/EddyVerbruggen/nativescript-plugin-firebase") and refer [its documentation on messaging]("https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md").
3
+
#### 1. Add the plugin to your app
4
+
Go to your app's root folder in terminal app and execute
3
5
```bash
4
6
tns plugin add nativescript-plugin-firebase
5
7
```
6
8
> 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
9
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.
10
+
#### 2. Setup
11
+
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
12
10
-
3. Add some code [to handle a notification]("https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md#handling-a-notification")
13
+
#### 3. Initialization prerequisite
14
+
Make sure you [`require` the plugin in `app.ts` / `main.ts` / `main.aot.ts`](https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/55cfb4f69cf8939f9101712fed22383196b08d36/demo/app/app.ts#L5)
15
+
*before*`application.start()`, and do `init()`*after* the app has started (not in `app.ts` - not even in a timeout; move it out of `app.ts` entirely!). This ensures the notifications will be receivable in the background.
#### 4. Add some code [to handle a notification]("https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md#handling-a-notification")
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").
61
+
#### 5. Testing with messages
62
+
To test with real 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").
63
+
64
+
#### 6. Interactive Push Notifications -in push plugin they are set in the options argument passed to pushPlugin.register(options, callback) method. In Firebase plugin, it is done in a very similar way:
65
+
66
+
```js
67
+
import * as firebase from "nativescript-plugin-firebase";
68
+
import { messaging } from "nativescript-plugin-firebase/messaging";
69
+
...
70
+
const model = new messaging.PushNotificationModel();
71
+
model.iosSettings = new messaging.IosPushSettings();
72
+
model.iosSettings.interactiveSettings = new messaging.IosInteractivePushSettings();
73
+
model.iosSettings.interactiveSettings.actions = [<<array of IosInteractiveNotificationAction>>]
Some lines in the above example have been omitted. See [Firebase plugin's interactive notifications docs]("https://github.com/EddyVerbruggen/nativescript-plugin-firebase/blob/master/docs/MESSAGING.md#interactive-notifications-ios-only-for-now") for more details.
44
85
45
-
4.
86
+
#### 7. areNotificationsEnabled() API
87
+
In Firebase plugin it is pretty similar to the one in push-plugin, and even simpler to use:
46
88
47
-
-----------
89
+
```js
90
+
import * as firebase from "nativescript-plugin-firebase";
48
91
49
-
2. You can go to demos and see there but below are how some usages of push-plugin translate to firebase:
0 commit comments