|
| 1 | +# Development Workflow |
| 2 | + |
| 3 | +<!-- TOC depthFrom:2 --> |
| 4 | + |
| 5 | +- [Prerequisites](#prerequisites) |
| 6 | +- [Develop locally](#develop-locally) |
| 7 | +- [Build the plugin](#build-the-plugin) |
| 8 | +- [Testing the plugin](#testing-the-plugin) |
| 9 | + |
| 10 | +<!-- /TOC --> |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +- Install your native toolchain and NativeScript as [described in the docs](https://docs.nativescript.org/start/quick-setup) |
| 15 | + |
| 16 | +- Review [NativeScript plugins documentation](https://docs.nativescript.org/plugins/plugins) for more details on plugins development |
| 17 | + |
| 18 | +## Develop locally |
| 19 | + |
| 20 | +For local development we recommend using the npm commands provided in the plugin's package.json |
| 21 | + |
| 22 | +To run and develop using TypeScript demo: |
| 23 | + |
| 24 | +```bash |
| 25 | +# Go to demo directory |
| 26 | +cd push-plugin/demo |
| 27 | +# Build the plugin. This compiles all TypeScript files in the plugin directory, which is referenced in the demo's package.json |
| 28 | +npm run build.plugin |
| 29 | +# Install demo dependencies |
| 30 | +npm i |
| 31 | +# Run the demo for iOS or Android. |
| 32 | +tns run ios |
| 33 | +tns run android |
| 34 | +``` |
| 35 | + |
| 36 | +After all the changes are done make sure to test them in all the demo app. |
| 37 | + |
| 38 | +Available npm commands from the plugin source directory: |
| 39 | + |
| 40 | +- `build` - builds the plugin so it can be used in the demo app. |
| 41 | +- `tslint` - check plugin's TypeScript sources for linting errors. |
| 42 | +- `clean` - clean the demo and plugin directories. |
| 43 | + |
| 44 | +## Build the plugin |
| 45 | + |
| 46 | +In order to build the native projects in the `native-src` directory, you need to have Xcode for the ios native project and Java or Android Studio for the Gradle build of the Android native project. Note that this is not required if you don't plan to update the native code - prebuilt binaries for iOS and Android are included in the `src/platforms` directory. |
| 47 | + |
| 48 | +## Testing the plugin |
| 49 | + |
| 50 | +Before building and running the demo for the first time, you should change the application ID (set by default to `org.nativescript.ppTest`) in the `demo/package.json` file to match your application in Firebase and/or provision in iOS. For Android, you should also update the `demo/app/App_Resources/Android/app.gradle` file with the new application ID. |
| 51 | + |
| 52 | +- Android - make sure you have added your `google-services.json` file to the `demo/app/App_Resources/Android` directory and that you have updated the `demo/app/main-view-model.ts` file with the sender ID of from your Firebase configuration. After the demo app is started the console will show the registration token of the device. For example: |
| 53 | + |
| 54 | + w7ycrQS0sU:APA91bHCAxiFqonJb77cc785txYZ_0nrWe_sLRZm_nG32h4lhaJhZw-mquBh0rlmaoRVQBhnRsWiMTOWOcbCzuvGCOVKo7UAxog8JEufQO-nOJo3C2cMpPsT9RfiZVgaDc2tK9ezRUf9 |
| 55 | + |
| 56 | + To test push notifications for the device, you can use the following web request: |
| 57 | + |
| 58 | + curl -X POST --header "Authorization: key=<YOUR_SERVER_KEY_HERE>" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"notification\":{\"title\": \"My title\", \"text\": \"My text\", \"badge\": \"1\", \"sound\": \"default\"}, \"data\":{\"foo\":\"bar\"}, \"priority\": \"High\", \"to\": \"<YOUR_DEVICE_TOKEN_HERE>\"}" |
| 59 | + |
| 60 | + where <YOUR_SERVER_KEY_HERE> is the Server key from the Firebase Cloud Messaging Settings page and <YOUR_DEVICE_TOKEN_HERE> is the token you copied from the console. |
| 61 | + |
| 62 | +- iOS - make sure that you are using the correct provisioning profile and app ID with enabled APNs. After the application is started the console will show the registration token for the device. For example: |
| 63 | + |
| 64 | + 7058206f33224ff472976d5a80a1c913b4133c5815cca829d2e4d92a82e1c3b6 |
| 65 | + |
| 66 | + To test push notifications for the device, you can use a third party app like [Pusher](https://github.com/noodlewerk/NWPusher). Open the app, load the correct push certificate and use the device ID from the console to send a message. |
| 67 | + |
| 68 | +For details on plugins development workflow, read [NativeScript plugins documentation](https://docs.nativescript.org/plugins/building-plugins#step-2-set-up-a-development-workflow) covering that topic. |
0 commit comments