diff options
Diffstat (limited to 'StoneIsland/plugins/phonegap-plugin-push/docs')
6 files changed, 323 insertions, 727 deletions
diff --git a/StoneIsland/plugins/phonegap-plugin-push/docs/API.md b/StoneIsland/plugins/phonegap-plugin-push/docs/API.md index 866fd28c..e0481af8 100644 --- a/StoneIsland/plugins/phonegap-plugin-push/docs/API.md +++ b/StoneIsland/plugins/phonegap-plugin-push/docs/API.md @@ -11,7 +11,7 @@ - [push.subscribe()](#pushsubscribetopic-successhandler-errorhandler) - [push.unsubscribe()](#pushunsubscribetopic-successhandler-errorhandler) - [push.setApplicationIconBadgeNumber() - iOS & Android only](#pushsetapplicationiconbadgenumbersuccesshandler-errorhandler-count---ios--android-only) -- [push.getApplicationIconBadgeNumber() - iOS & Android only](#pushgetapplicationiconbadgenumbersuccesshandler-errorhandler---ios--android-only) +- [push.getApplicationIconBadgeNumber() - iOS only](#pushgetapplicationiconbadgenumbersuccesshandler-errorhandler---ios-only) - [push.finish() - iOS only](#pushfinishsuccesshandler-errorhandler-id---ios-only) - [push.clearAllNotifications() - iOS & Android only](#pushclearallnotificationssuccesshandler-errorhandler---ios--android-only) @@ -39,6 +39,7 @@ All available option attributes are described bellow. Currently, there are no Wi Attribute | Type | Default | Description --------- | ---- | ------- | ----------- +`android.senderID` | `string` | | Maps to the project number in the Google Developer Console. `android.icon` | `string` | | Optional. The name of a drawable resource to use as the small-icon. The name should not include the extension. `android.iconColor` | `string` | | Optional. Sets the background color of the small icon on Android 5.0 and greater. [Supported Formats](http://developer.android.com/reference/android/graphics/Color.html#parseColor(java.lang.String)) `android.sound` | `boolean` | `true` | Optional. If `true` it plays the sound specified in the push data or the default system sound. @@ -46,16 +47,13 @@ Attribute | Type | Default | Description `android.clearBadge` | `boolean` | `false` | Optional. If `true` the icon badge will be cleared on init and before push messages are processed. `android.clearNotifications` | `boolean` | `true` | Optional. If `true` the app clears all pending notifications when it is closed. `android.forceShow` | `boolean` | `false` | Optional. Controls the behavior of the notification when app is in foreground. If `true` and app is in foreground, it will show a notification in the notification drawer, the same way as when the app is in background (and `on('notification')` callback will be called *only when the user clicks the notification*). When `false` and app is in foreground, the `on('notification')` callback will be called immediately. -`android.topics` | `array` | `[]` | Optional. If the array contains one or more strings each string will be used to subscribe to a FcmPubSub topic. -`android.messageKey` | `string` | `message` | Optional. The key to search for text of notification. -`android.titleKey` | `string` | `'title'` | Optional. The key to search for title of notification. +`android.topics` | `array` | `[]` | Optional. If the array contains one or more strings each string will be used to subscribe to a GcmPubSub topic. #### Browser Attribute | Type | Default | Description --------- | ---- | ------- | ----------- `browser.pushServiceURL` | `string` | `http://push.api.phonegap.com/v1/push` | Optional. URL for the push server you want to use. -`browser.applicationServerKey` | `string` | `` | Optional. Your GCM API key if you are using VAPID keys. #### iOS @@ -75,9 +73,9 @@ The following properties are used if you want use GCM on iOS. Attribute | Type | Default | Description --------- | ---- | ------- | ----------- -`ios.fcmSandbox` | `boolean` | `false` | Whether to use prod or sandbox GCM setting. Defaults to false. -options -`ios.topics` | `array` | `[]` | Optional. If the array contains one or more strings each string will be used to subscribe to a FcmPubSub topic. +`ios.senderID` | `string` | `undefined` (Native) | Maps to the project number in the Google Developer Console. Setting this uses GCM for notifications instead of native +`ios.gcmSandbox` | `boolean` | `false` | Whether to use prod or sandbox GCM setting. Defaults to false. +`ios.topics` | `array` | `[]` | Optional. If the array contains one or more strings each string will be used to subscribe to a GcmPubSub topic. Note: only usable in conjunction with `senderID`. ##### How GCM on iOS works. @@ -87,12 +85,12 @@ What happens is on the device side is that it registers with APNS, then that reg When you send a message to GCM using that ID, what it does is look up the APNS registration ID on it's side and forward the message you sent to GCM on to APSN to deliver to your iOS device. -Make sure that the certificate you build with matches your `fcmSandbox` value. +Make sure that the certificate you build with matches your `gcmSandbox` value. -- If you build your app as development and set `fcmSandbox: false` it will fail. -- If you build your app as production and set `fcmSandbox: true` it will fail. -- If you build your app as development and set `fcmSandbox: true` but haven't uploaded the development certs to Google it will fail. -- If you build your app as production and set `fcmSandbox: false` but haven't uploaded the production certs to Google it will fail. +- If you build your app as development and set `gcmSandbox: false` it will fail. +- If you build your app as production and set `gcmSandbox: true` it will fail. +- If you build your app as development and set `gcmSandbox: true` but haven't uploaded the development certs to Google it will fail. +- If you build your app as production and set `gcmSandbox: false` but haven't uploaded the production certs to Google it will fail. > Note: The integration between GCM and APNS is a bit finicky. Personally, I feel it is much better to send pushes to Android using GCM and pushes to iOS using APNS which this plugin does support. @@ -101,6 +99,7 @@ Make sure that the certificate you build with matches your `fcmSandbox` value. ```javascript var push = PushNotification.init({ android: { + senderID: "12345679" }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' @@ -160,14 +159,12 @@ The event `registration` will be triggered on each successful registration with Parameter | Type | Description --------- | ---- | ----------- `data.registrationId` | `string` | The registration ID provided by the 3rd party remote push service. -`data.registrationType` | `string` | The registration type of the 3rd party remote push service. Either FCM or APNS. ### Example ```javascript push.on('registration', function(data) { - console.log(data.registrationId); - console.log(data.registrationType); + console.log(data.registrationId); }); ``` @@ -206,7 +203,6 @@ Parameter | Type | Description `data.additionalData` | `Object` | An optional collection of data sent by the 3rd party push service that does not fit in the above properties. `data.additionalData.foreground` | `boolean` | Whether the notification was received while the app was in the foreground `data.additionalData.coldstart` | `boolean` | Will be `true` if the application is started by clicking on the push notification, `false` if the app is already started. -`data.additionalData.dismissed` | `boolean` | Is set to `true` if the notification was dismissed by the user ### Example @@ -356,7 +352,7 @@ push.setApplicationIconBadgeNumber(function() { }, 2); ``` -## push.getApplicationIconBadgeNumber(successHandler, errorHandler) - iOS & Android only +## push.getApplicationIconBadgeNumber(successHandler, errorHandler) - iOS only Get the current badge count visible when the app is not running diff --git a/StoneIsland/plugins/phonegap-plugin-push/docs/EXAMPLES.md b/StoneIsland/plugins/phonegap-plugin-push/docs/EXAMPLES.md index 32bc2e5f..8481e7bc 100644 --- a/StoneIsland/plugins/phonegap-plugin-push/docs/EXAMPLES.md +++ b/StoneIsland/plugins/phonegap-plugin-push/docs/EXAMPLES.md @@ -11,6 +11,7 @@ phonegap create my-app --template phonegap-template-push ```javascript var push = PushNotification.init({ android: { + senderID: "12345679" }, browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' diff --git a/StoneIsland/plugins/phonegap-plugin-push/docs/INSTALLATION.md b/StoneIsland/plugins/phonegap-plugin-push/docs/INSTALLATION.md index ea8f6918..830bbdd7 100644 --- a/StoneIsland/plugins/phonegap-plugin-push/docs/INSTALLATION.md +++ b/StoneIsland/plugins/phonegap-plugin-push/docs/INSTALLATION.md @@ -4,7 +4,6 @@ - [Android details](#android-details) - [Compilation](#compilation) - [Co-existing with Facebook Plugin](#co-existing-with-facebook-plugin) - - [Co-existing with plugins that use Firebase](#co-existing-with-plugins-that-use-firebase) - [Common errors](#common-errors) - [minSdkVersion === 14](#minsdkversion--14) - [Multidex](#multidex) @@ -17,65 +16,52 @@ - [Bitcode](#bitcode) - [CocoaPods](#cocoapods) - [Common CocoaPod Installation issues](#common-cocoapod-installation-issues) - - [CocoaPod Disk Space](#cocoapod-disk-space) - - [Library not found for -lPods-Appname](#library-not-found-for--lPods-Appname) - - [Library not found for -lGoogleToolboxForMac](#library-not-found-for--lPods-Appname) - [Additional Resources](#additional-resources) ## Installation Requirements Plugin version | Cordova CLI | Cordova Android | Cordova iOS | CocoaPods ---- | ---- | ---- | ---- | ---- -2.0.0 | 7.0.0 | 6.2.1 | 4.4.0 | 1.1.1 1.9.0 | 6.4.0 | 6.0.0 | 4.3.0 | 1.1.1 1.8.0 | 3.6.3 | 4.0.0 | 4.1.0 | N/A To install from the command line: ``` -phonegap plugin add phonegap-plugin-push +phonegap plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX" ``` or ``` -cordova plugin add phonegap-plugin-push +cordova plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX" ``` It is also possible to install via repo url directly ( unstable ) ``` -phonegap plugin add https://github.com/phonegap/phonegap-plugin-push +phonegap plugin add https://github.com/phonegap/phonegap-plugin-push --variable SENDER_ID="XXXXXXX" ``` or ``` -cordova plugin add https://github.com/phonegap/phonegap-plugin-push +cordova plugin add https://github.com/phonegap/phonegap-plugin-push --variable SENDER_ID="XXXXXXX" ``` -As of version 2.0.0 the SENDER_ID parameter has been removed at install time. Instead you put your google-services.json (Android) and/or GoogleService-Info.plist in the root folder of your project and then add the following lines into your config.xml. +Where the `XXXXXXX` in `SENDER_ID="XXXXXXX"` maps to the project number in the [Google Developer Console](https://www.google.ca/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwikqt3nyPjMAhXJ5iYKHR0qDcsQFggbMAA&url=https%3A%2F%2Fconsole.developers.google.com%2F&usg=AFQjCNF0eH059mv86nMIlRmfsf42kde-wA&sig2=BQ2BJpchw1CpGt87sk5p6w&bvm=bv.122852650,d.eWE). To find the project number login to the Google Developer Console, select your project and click the menu item in the screen shot below to display your project number. -In the platform tag for Android add the resource-file tag: + -``` -<platform name="android"> - <resource-file src="google-services.json" target="google-services.json" /> -</platform> -``` - -In the platform tag for iOS add the resource-file tag: - -``` -<platform name="ios"> - <resource-file src="GoogleService-Info.plist" /> -</platform> -``` +If you are not creating an Android application you can put in anything for this value. > Note: if you are using Ionic you may need to specify the SENDER_ID variable in your package.json. ``` "cordovaPlugins": [ { + "variables": { + "SENDER_ID": "XXXXXXX" + }, "locator": "phonegap-plugin-push" } ] @@ -84,17 +70,23 @@ In the platform tag for iOS add the resource-file tag: > Note: You need to specify the SENDER_ID variable in your config.xml if you plan on installing/restoring plugins using the prepare method. The prepare method will skip installing the plugin otherwise. ``` -<plugin name="phonegap-plugin-push" spec="2.0.0" /> +<plugin name="phonegap-plugin-push" spec="1.6.0"> + <param name="SENDER_ID" value="XXXXXXX" /> +</plugin> ``` ## Android details ### Compilation -As of version 2.0.0 the plugin has been switched to using pinned version of Gradle libraries. You will need to ensure that you have installed the following items through the Android SDK Manager: +As of version 1.3.0 the plugin has been switched to using Gradle/Maven for building. + +You will need to ensure that you have installed the following items through the Android SDK Manager: -- Android Support Library version 25.1.0 -- FirebaseMessaging Library version 9.8.0 +- Android Support Library version 23 or greater +- Local Maven repository for Support Libraries (formerly Android Support Repository) version 20 or greater +- Google Play Services version 27 or greater +- Google Repository version 22 or greater  @@ -121,30 +113,6 @@ or cordova plugin add --save cordova-plugin-facebook4 --variable APP_ID="App ID" --variable APP_NAME="App Name" ``` -### Co-existing with plugins that use Firebase - -Problems may arise when push plugin is used along plugins that implement Firebase functionality (cordova-plugin-firebase-analytics, for example). Firebase uses `@string/google_app_id`, as does the push plugin, though the value format differs, causing problems like this: `Invalid google_app_id. Firebase Analytics disabled`. - -To make the two work together, you need to migrate your GCM project from Google console to Firebase console: - -1) In Firebase console - [import your existing GCM project](https://firebase.google.com/support/guides/google-android#migrate_your_console_project), don't create a new one. -2) Set your `SENDER_ID` variable to match the id of your imported Firebase project. In case of cordova, your `config.xml` would look something like this: -```xml -<plugin name="phonegap-plugin-push" spec="~1.10.0"> - <variable name="SENDER_ID" value="1:956432534015:android:df201d13e7261425" /> -</plugin> -``` -3) In your JavaScript, when you init the PushPlugin, senderID remains the same format as before: -```javascript -PushNotification.init({ - android: { - senderID: 956432534015 - } -}); -``` - -*Note:* No changes on the back-end side are needed: [even though recommended](https://developers.google.com/cloud-messaging/android/android-migrate-fcm#update_server_endpoints), it isn't yet required and sending messages through GCM gateway should work just fine. - ### Common errors #### minSdkVersion === 14 @@ -255,21 +223,11 @@ cordova platform update ios@4.0.0 ### CocoaPods -Required `cordova-cli` minimum version: `6.4.0` - -Required `cordova-ios` minimum version: `4.3.0` - -Required `CocoaPods` minimum version: `1.0.1` +Required `cordova-cli` version: `6.4.0` +Required `cordova-ios` version: `4.3.0` -To install CocoaPods, please follow the installation instructions [here](https://guides.cocoapods.org/using/getting-started). After installing CocoaPods, please run: - - pod setup - -This will clone the required CocoaPods specs-repo into your home folder at `~/.cocoapods/repos`, so it might take a while. See the [CocoaPod Disk Space](#cocoapod-disk-space) section below for more information. - - -Version `2.0.0` (and above) of this plugin supports [CocoaPods](https://cocoapods.org) installation of the [Firebase Cloud Messaging](https://cocoapods.org/pods/FirebaseMessaging) library. +Version `1.9.0` (and above) of this plugin supports [CocoaPods](https://cocoapods.org) installation of the [Google Cloud Messaging](https://cocoapods.org/pods/GoogleCloudMessaging) library. If you are installing this plugin using `npm`, and you are using version `6.1.0` or greater of the `cordova-cli`, it will automatically download the right version of this plugin for both your platform and cli. @@ -297,55 +255,59 @@ Failed to install 'phonegap-plugin-push':Error: pod: Command failed with exit co Error: pod: Command failed with exit code 1 ``` -Please run the command `pod repo update` and re-install the plugin. You would only run `pod repo update` if you have the specs-repo already cloned on your machine through `pod setup`. - -##### CocoaPod Disk Space - -Running `pod setup` can take over 1 GB of disk space and that can take quite some time to download over a slow internet connection. If you are having issues with disk space/network try this neat hack from @VinceOPS. +Please run the command `pod repo update` and re-install the plugin. -``` -git clone --verbose --depth=1 https://github.com/CocoaPods/Specs.git ~/.cocoapods/repos/master -pod setup --verbose -``` +## Additional Resources -##### Library not found for -lPods-Appname +The push plugin enables you to play sounds and display different icons during push (Android only). These additional resources need to be added to your projects `platforms` directory in order for them to be included into your final application binary. One way of doing it is to create a hook to do the copying for you on each build. -If you open the app in Xcode and you get an error like: +First create a `scripts` directory in the root of your project. Next add a file to the scripts directory called `copy_resource_files.js`. The contents of the file will look something like this: -``` -ld: library not found for -lPods-Appname -clang: error: linker command failed with exit code 1 -``` +```javascript +#!/usr/bin/env node -Then you are opening the .xcodeproj file when you should be opening the .xcworkspace file. +// each object in the array consists of a key which refers to the source and +// the value which is the destination. +var filestocopy = [{ + "resources/android/images/logo.png": + "platforms/android/res/drawable/logo.png" +}, { + "resources/android/sounds/ring.mp3": + "platforms/android/res/raw/ring.mp3" +}, { + "resources/ios/sounds/ring.caf": + "platforms/ios/YourAppName/ring.caf" +}, ]; -##### Library not found for -lGoogleToolboxForMac +var fs = require('fs'); +var path = require('path'); -Trying to build for iOS using the latest cocoapods (1.2.1) but failed with the following error (from terminal running cordova build ios): +// no need to configure below +var rootdir = process.argv[2]; +filestocopy.forEach(function(obj) { + Object.keys(obj).forEach(function(key) { + var val = obj[key]; + var srcfile = path.join(rootdir, key); + var destfile = path.join(rootdir, val); + //console.log("copying "+srcfile+" to "+destfile); + var destdir = path.dirname(destfile); + if (fs.existsSync(srcfile) && fs.existsSync(destdir)) { + fs.createReadStream(srcfile).pipe( + fs.createWriteStream(destfile)); + } + }); +}); ``` -ld: library not found for -lGoogleToolboxForMac -``` - -Workarounds are to add the platform first and install the plugins later, or to manually run pod install on projectName/platforms/ios. -## Additional Resources - -The push plugin enables you to play sounds and display different icons during push (Android only). These additional resources need to be added to your projects `platforms` directory in order for them to be included into your final application binary. +Obviously, you'll need to modify the `filestocopy` variable to suit your needs. Pay attention to the destination path on iOS where you will need to replace `YourAppName`. -You can now use the `resource-file` tag to deliver the image and sound files to your application. For example if you wanted to include an extra image file for only your Android build you would add the `resource-file` tag to your android `platform` tag: +Next open up your `config.xml` file and add the following line: +```xml +<hook type="before_build" src="scripts/copy_resource_files.js" /> ``` -<platform name="android"> - <resource-file src="myImage.png" target="res/drawable/myImage.png" /> -</platform> -``` - -or if you wanted to include a sound file for iOS: +Now, when you build your app the files will get copied into your platforms directory for you. -``` -<platform name="ios"> - <resource-file src="mySound.caf" /> -</platform> -``` +If you are using PhoneGap Build check out these instructions on [Additional Resources](PHONEGAP_BUILD.md#additional-resources) diff --git a/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md b/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md index 431b5a4e..b446612e 100644 --- a/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md +++ b/StoneIsland/plugins/phonegap-plugin-push/docs/PAYLOAD.md @@ -3,7 +3,6 @@ - [Background Events](#push-message-arrives-with-app-in-background) - [Tap Events](#user-clicks-on-notification-in-notification-center) - [Android Behaviour](#android-behaviour) - - [Notification vs Data Payloads](#notification-vs-data-payloads) - [Localization](#localization) - [Images](#images) - [Sound](#sound) @@ -16,14 +15,12 @@ - [Priority in Notifications](#priority-in-notifications) - [Picture Messages](#picture-messages) - [Background Notifications](#background-notifications) - - [Use of content_available: true](#use-of-content-available-true) - - [Caching](#caching) + - [Use of content-available: true](#use-of-content-available-true) - [Huawei and Xiaomi Phones](#huawei-and-xiaomi-phones) - [Application force closed](#application-force-closed) - [Visibility](#visibility-of-notifications) - [Badges](#badges) - [Support for Twilio Notify](#support-for-twilio-notify) - - [Notification ID](#notification-id) - [iOS Behaviour](#ios-behaviour) - [Sound](#sound-1) - [Background Notifications](#background-notifications-1) @@ -70,66 +67,6 @@ Some ways to handle this *double* event are: # Android Behaviour -## Notification vs Data Payloads - -Notifications behave differently depending on the foreground/background state of the receiving app and the payload you send to the app. - -For instance if you send the following payload: - -``` -{ - "notification": { - "title": "Test Notification", - "body": "This offer expires at 11:30 or whatever", - "notId": 10 - } -} -``` - -When your app is in the foreground any `on('notification')` handlers you have registered will be called. However if your app is in the background the notification will show up in the system tray. Clicking on the notification in the system tray will start the app but your `on('notification')` handler will not be called as messages with only `notification` payloads will not cause the plugins `onMessageReceived` method to be called. - -If you send a payload with a mix of `notification` & `data` objects like this: - -``` -{ - "notification": { - "title": "Test Notification", - "body": "This offer expires at 11:30 or whatever", - "notId": 10 - }, - "data" : { - "surveyID": "ewtawgreg-gragrag-rgarhthgbad" - } -} -``` - -When your app is in the foreground any `on('notification')` handlers you have registered will be called. If your app is in the background the notification will show up in the system tray. Clicking on the notification in the system tray will start the app and your `on('notification')` handler will not be called as messages with only `notification` payloads will not cause the plugins `onMessageReceived` method to be called. - -My recommended format for your push payload when using this plugin (while it differs from Google's docs) works 100% of the time: - -``` -{ - "data" : { - "title": "Test Notification", - "body": "This offer expires at 11:30 or whatever", - "notId": 10, - "surveyID": "ewtawgreg-gragrag-rgarhthgbad" - } -} -``` - -When your app is in the foreground any `on('notification')` handlers you have registered will be called. If your app is in the background the notification will show up in the system tray. Clicking on the notification in the system tray will start the app and your `on('notification')` handler will be called and the event received by your `on('notification')` handler will get the following data: - -``` -{ - "message": "This offer expires at 11:30 or whatever", - "title": "Test Notification", - "additionalData": { - "surveyID": "ewtawgreg-gragrag-rgarhthgbad" - } -} -``` - ## Localization Plugin supported localization from resources for: title, message and summaryText. @@ -158,32 +95,22 @@ Or use localization with formatted constants. } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: {"locKey": "push_app_title"}, - message: 'Simple non-localizable text for message!' - // Constant with formatted params - // message: {"locKey": "push_message_fox", "locData": ["fox", "dog"]}); - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', {"locKey": "push_app_title"}); +message.addData('message', 'Simple non-localizable text for message!'); +// Constant with formatted params +// message.addData('message', {"locKey": "push_message_fox", "locData": ["fox", "dog"]}); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -202,8 +129,9 @@ By default the icon displayed in your push notification will be your apps icon. ```javascript var push = PushNotification.init({ "android": { + "senderID": "12345679" }, - "browser": { + browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, "ios": { @@ -226,10 +154,11 @@ In order to get a better user experience you can specify an alternate icon and b ```javascript var push = PushNotification.init({ "android": { + "senderID": "123456789", "icon": "phonegap", "iconColor": "blue" }, - "browser": { + browser: { pushServiceURL: 'http://push.api.phonegap.com/v1/push' }, "ios": { @@ -241,8 +170,7 @@ var push = PushNotification.init({ }); ``` -Where *icon* is the name of an `.png` image file in the Android `res/drawable` folder. For example: `platforms/android/res/drawable/phonegap.png` -Writing a hook to describe how to copy an image to the Android `res/drawable` folder is out of scope for this README but there is an [excellent tutorial](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/) that you can copy. +Where *icon* is the name of an image in the Android *drawables* folder. Writing a hook to describe how to copy an image to the Android *drawables* folder is out of scope for this README but there is an [excellent tutorial](http://devgirl.org/2013/11/12/three-hooks-your-cordovaphonegap-project-needs/) that you can copy. *iconColor* is one of the supported formats #RRGGBB or #AARRGGBB or one of the following names: 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuchsia', 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'. *iconColor* is supported on Android 5.0 and greater. @@ -252,48 +180,38 @@ Please follow the [Android icon design guidelines](https://www.google.com/design Additionally, each push can include a large icon which is used to personalize each push. The location of the image may one of three types. -The first is the `res/drawable` folder in your app. This JSON sent from GCM: +The first is the *drawables* folder in your app. This JSON sent from GCM: ```javascript { "registration_ids": ["my device id"], "data": { "title": "Large Icon", - "message": "Loaded from drawable folder", + "message": "Loaded from drawables folder", "image": "twitter" } } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Large Icon', - message: 'Loaded from drawables folder.', - image: 'twitter' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Large Icon'); +message.addData('message', 'Loaded from drawables folder.'); +message.addData('image', 'twitter'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` -Would look for the *twitter* image in the `res/drawable` folder and produce the following notification. +Would look for the *twitter* image in the drawables folder and produce the following notification.  @@ -310,35 +228,25 @@ The second is the *assets* folder in your app. This JSON sent from GCM: } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Large Icon', - message: 'Loaded from assets folder.', - image: 'www/image/logo.png' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Large Icon'); +message.addData('message', 'Loaded from assets folder.'); +message.addData('image', 'www/image/logo.png'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` -Would look for the *logo.png* file in the assets/www/img folder. Since your apps www folder gets copied into the Android assets folder it is an excellent spot to store the images without needing to write a hook to copy them to the `res/drawable` folder. It produces the following notification. +Would look for the *logo.png* file in the assets/www/img folder. Since your apps www folder gets copied into the Android assets folder it is an excellent spot to store the images without needing to write a hook to copy them to the *drawables* folder. It produces the following notification.  @@ -356,52 +264,6 @@ The third is the remote *URL*. This JSON sent from GCM: } ``` -Here is an example using fcm-node that sends the above JSON: - -```javascript -var FCM = require('fcm-node'); -// Replace these with your own values. -var apiKey = "replace with API key"; -var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Large Icon', - message: 'Loaded from URL', - image: 'https://dl.dropboxusercontent.com/u/887989/antshot.png' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } -}); -``` - -Produces the following notification. - - - -Finally the Material UI guidelines recommend using a circular icon for the large icon if the subject of the image is a person. This JSON sent from GCM: - -```javascript -{ - "registration_ids": ["my device id"], - "data": { - "title": "Large Circular Icon", - "message": "Loaded from URL", - "image": "https://pbs.twimg.com/profile_images/837060031895896065/VHIQ4oUf_400x400.jpg", - "image-type": "circle" - } -} -``` - Here is an example using node-gcm that sends the above JSON: ```javascript @@ -411,10 +273,9 @@ var apiKey = "replace with API key"; var deviceID = "my device id"; var service = new gcm.Sender(apiKey); var message = new gcm.Message(); -message.addData('title', 'Large Circular Icon'); +message.addData('title', 'Large Icon'); message.addData('message', 'Loaded from URL'); -message.addData('image', 'https://pbs.twimg.com/profile_images/837060031895896065/VHIQ4oUf_400x400.jpg'); -message.addData('image-type', 'circular'); +message.addData('image', 'https://dl.dropboxusercontent.com/u/887989/antshot.png'); service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { if(err) console.error(err); else console.log(response); @@ -423,7 +284,7 @@ service.send(message, { registrationTokens: [ deviceID ] }, function (err, respo Produces the following notification. - + ## Sound @@ -478,31 +339,21 @@ In order for your your notification to play a custom sound you will need to add } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Sound Test', - message: 'Loaded res/raw', - soundname: 'test' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Sound Test'); +message.addData('message', 'Loaded res/raw'); +message.addData('soundname', 'test'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -524,30 +375,20 @@ If you want to see multiple notifications in the shade you will need to provide } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Test Push', - message: 'Push number 1' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Test Push'); +message.addData('message', 'Push number 1'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -563,30 +404,20 @@ Followed by: } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Test Push', - message: 'Push number 2' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Test Push'); +message.addData('message', 'Push number 2'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -603,31 +434,21 @@ You will only see "Push number 2" in the shade. However, if you send: } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Test Push', - message: 'Push number 1', - notId: 1 - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Test Push'); +message.addData('message', 'Push number 1'); +message.addData('notId', 1); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -644,31 +465,21 @@ and: } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Test Push', - message: 'Push number 2', - notId: 2 - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Test Push'); +message.addData('message', 'Push number 2'); +message.addData('notId', 2); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -690,32 +501,22 @@ A better alternative to stacking your notifications is to use the inbox style to } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'My Title', - message: 'My first message', - style: 'inbox', - summaryText: 'There are %n% notifications' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'My Title'); +message.addData('message', 'My first message'); +message.addData('style', 'inbox'); +message.addData('summaryText', 'There are %n% notifications'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -737,32 +538,22 @@ But, if you follow it up with subsequent notifications like: } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'My Title', - message: 'My second message', - style: 'inbox', - summaryText: 'There are %n% notifications' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'My Title'); +message.addData('message', 'My second message'); +message.addData('style', 'inbox'); +message.addData('summaryText', 'There are %n% notifications'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -790,34 +581,24 @@ Your notification can include a maximum of three action buttons. If you wish to } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'AUX Scrum', - message: 'Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.', - actions: [ - { icon: "emailGuests", title: "EMAIL GUESTS", callback: "app.emailGuests", foreground: true}, - { icon: "snooze", title: "SNOOZE", callback: "app.snooze", foreground: false}, - ] - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'AUX Scrum'); +message.addData('message', 'Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.'); +message.addData('actions', [ + { "icon": "emailGuests", "title": "EMAIL GUESTS", "callback": "app.emailGuests", "foreground": true}, + { "icon": "snooze", "title": "SNOOZE", "callback": "app.snooze", "foreground": false}, +]); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -847,34 +628,24 @@ Your notification can include action buttons. If you wish to include an icon alo } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'AUX Scrum', - message: 'Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.', - actions: [ - { "icon": "emailGuests", "title": "EMAIL GUESTS", "callback": "app.emailGuests", "foreground": false, "inline": true}, - { "icon": "snooze", "title": "SNOOZE", "callback": "app.snooze", "foreground": false}, - ] - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'AUX Scrum'); +message.addData('message', 'Scrum: Daily touchbase @ 10am Please be on time so we can cover everything on the agenda.'); +message.addData('actions', [ + { "icon": "emailGuests", "title": "EMAIL GUESTS", "callback": "app.emailGuests", "foreground": false, "inline": true}, + { "icon": "snooze", "title": "SNOOZE", "callback": "app.snooze", "foreground": false}, +]); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -941,31 +712,21 @@ You can use a Led notifcation and choose the color of it. Just add a `ledColor` } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Green LED', - message: 'This is my message with a Green LED', - ledColor: [0, 0, 255, 0] - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Green LED'); +message.addData('message', 'This is my message with a Green LED'); +message.addData('ledColor', [0, 0, 255, 0]); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -984,31 +745,21 @@ You can set a Vibration Pattern for your notifications. Just add a `vibrationPat } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Vibration Pattern', - message: 'Device should wait for 2 seconds, vibrate for 1 second then be silent for 500 ms then vibrate for 500 ms', - vibrationPattern: [2000, 1000, 500, 500] - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Vibration Pattern'); +message.addData('message', 'Device should wait for 2 seconds, vibrate for 1 second then be silent for 500 ms then vibrate for 500 ms'); +message.addData('vibrationPattern', [2000, 1000, 500, 500]); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -1027,31 +778,21 @@ You can set a priority parameter for your notifications. This priority value det } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'This is a maximum priority Notification', - message: 'This notification should appear in front of all others', - priority: 2 - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'This is a maximum priority Notification'); +message.addData('message', 'This notification should appear in front of all others'); +message.addData('priority', 2); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -1074,32 +815,23 @@ Perhaps you want to include a large picture in the notification that you are sen } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Big Picture', - message: 'This is my big picture message', - picture: 'http://36.media.tumblr.com/c066cc2238103856c9ac506faa6f3bc2/tumblr_nmstmqtuo81tssmyno1_1280.jpg', - summaryText: 'The internet is built on cat pictures' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Big Picture'); +message.addData('message', 'This is my big picture message'); +message.addData('style', 'picture'); +message.addData('picture', 'http://36.media.tumblr.com/c066cc2238103856c9ac506faa6f3bc2/tumblr_nmstmqtuo81tssmyno1_1280.jpg'); +message.addData('summaryText', 'The internet is built on cat pictures'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -1127,32 +859,22 @@ First the JSON you send from GCM will need to include `"content-available": "1"` } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - "to": deviceID, - "data": { - "title": 'Test Push', - "message": 'Push number 1', - "info": 'super secret info', - "content-available": '1' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Test Push'); +message.addData('message', 'Push number 1'); +message.addData('info', 'super secret info'); +message.addData('content-available', '1'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -1169,38 +891,28 @@ or if you want the payload to be delivered directly to your app without anything } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - "to": deviceID, - "data": { - "info": 'super secret info', - "content-available": '1' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('info', 'super secret info'); +message.addData('content-available', '1'); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` If do not want this type of behaviour just omit `"content-available": 1` from your push data and your `on('notification')` event handler will not be called. -### Use of content_available: true +### Use of content-available: true -The [GCM docs](https://developers.google.com/cloud-messaging/http-server-ref#downstream-http-messages-json) will tell you to send a data payload of: +The GCM docs will tell you to send a data payload of: ```javascript { @@ -1214,9 +926,9 @@ The [GCM docs](https://developers.google.com/cloud-messaging/http-server-ref#dow } ``` -Where the `content_available` property is part of the main payload object. Setting the property in this part of the payload will result in the PushPlugin not getting the data correctly. Setting `content_available: true` will cause the Android OS to handle the push payload for you and not pass the data to the PushPlugin. +Where the `content-available` property is part of the main payload object. Setting the property in this part of the payload will result in the PushPlugin not getting the data correctly. Setting `content-available: true` will cause the Android OS to handle the push payload for you and not pass the data to the PushPlugin. -Instead move `content_available: true` into the `data` object of the payload. The property name changes slightly to use a `-` instead of an `_`. So, `content_available` becomes `content-available` and `true` becomes `1` as per the example below: +Instead move `content-available: true` into the `data` object of the payload and set it to `1` as per the example below: ```javascript { @@ -1235,8 +947,7 @@ Instead move `content_available: true` into the `data` object of the payload. Th These phones have a particular quirk that when the app is force closed that you will no longer be able to receive notifications until the app is restarted. In order for you to receive background notifications: - On your Huawei device go to Settings > Protected apps > check "My App" where. -- On your Xiaomi make sure your phone has the "Auto-start" property enabled for your app. -- On your Asus make sure your phone has the "Auto-start" property enabled for your app. +- On your Xiaomi makes sure your phone has the "Auto-start" property enabled for your app. ### Application force closed @@ -1282,50 +993,24 @@ If you add `force-start: 1` to the data payload the application will be restarte } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - "data": { - "title": 'Force Start', - "message": 'This notification should restart the app', - "force-start": '1' - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Force Start'); +message.addData('message', 'This notification should restart the app'); +message.addData('force-start', 1); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` -### Caching - -By default, when a notification arrives and 'content-available' is set to '1', the plugin will try to deliver the data payload even if the app is not running. In that case, the payload is cached and may be delivered when the app is started again. To disable this behavior, you can set a `no-cache` flag in the notification payload. 0: caching enabled (default), 1: caching disabled. - -```javascript -{ - "registration_ids": ["my device id"], - "data": { - "title": "Push without cache", - "message": "When the app is closed, this notification will not be cached", - "content-available": "1", - "no-cache": "1" - } -} -``` - ## Visibility of Notifications You can set a visibility parameter for your notifications. Just add a `visibility` field in your notification. -1: secret, 0: private (default), 1: public. `Secret` shows only the most minimal information, excluding even the notification's icon. `Private` shows basic information about the existence of this notification, including its icon and the name of the app that posted it. The rest of the notification's details are not displayed. `Public` Shows the notification's full content. @@ -1341,31 +1026,21 @@ You can set a visibility parameter for your notifications. Just add a `visibilit } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'This is a public Notification', - message: 'You should be able to read this notification on your lock screen', - visibility: 1 - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'This is a public Notification'); +message.addData('message', 'You should be able to read this notification on your lock screen'); +message.addData('visibility', 1); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -1386,31 +1061,21 @@ In order to set the badge number you will need to include the `badge` property i } ``` -Here is an example using fcm-node that sends the above JSON: +Here is an example using node-gcm that sends the above JSON: ```javascript -var FCM = require('fcm-node'); +var gcm = require('node-gcm'); // Replace these with your own values. var apiKey = "replace with API key"; var deviceID = "my device id"; -var fcm = new FCM(apiKey); - -var message = { - to: deviceID, - data: { - title: 'Badge Test', - message: 'Badges, we don\'t need no stinking badges', - badge: 7 - } -}; - -fcm.send(message, function(err, response){ - if (err) { - console.log(err); - console.log("Something has gone wrong!"); - } else { - console.log("Successfully sent with response: ", response); - } +var service = new gcm.Sender(apiKey); +var message = new gcm.Message(); +message.addData('title', 'Badge Test'); +message.addData('message', 'Badges, we don\'t need no stinking badges'); +message.addData('badge', 7); +service.send(message, { registrationTokens: [ deviceID ] }, function (err, response) { + if(err) console.error(err); + else console.log(response); }); ``` @@ -1448,17 +1113,11 @@ The JSON received by your app will comply with the standards described in the se Note: "sound" and "soundname" are equivalent and are considered to be the same by the plugin. -## Notification ID - -When setting the notification ID or `notId` please make sure that you are not exceeding the [MAX_INT](https://developer.android.com/reference/java/lang/Integer.html#MAX_VALUE) value for Android. Using a value larger than MAX_INT will throw an exception which will be caught by the plugin and it will use a default value of `0`. - -This means you can't use the JavaScript's `Date.getMilliseconds()` or Java's `System.currentTimeMillis()` as they will give you a value greater than MAX_INT. - # iOS Behaviour ## Sound -In order for your notification to play a custom sound you will need to add the files to root of your iOS project. The files must be in the proper format. See the [Local and Remote Notification Programming Guide](https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/SupportingNotificationsinYourApp.html#//apple_ref/doc/uid/TP40008194-CH4-SW10) for more info on proper file formats and how to convert existing sound files. +In order for your notification to play a custom sound you will need to add the files to root of your iOS project. The files must be in the proper format. See the [Local and Remote Notification Programming Guide](https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/IPhoneOSClientImp.html#//apple_ref/doc/uid/TP40008194-CH103-SW6) for more info on proper file formats and how to convert existing sound files. Then send the follow JSON from APNS: diff --git a/StoneIsland/plugins/phonegap-plugin-push/docs/PHONEGAP_BUILD.md b/StoneIsland/plugins/phonegap-plugin-push/docs/PHONEGAP_BUILD.md index 7f460738..8a95d6a1 100644 --- a/StoneIsland/plugins/phonegap-plugin-push/docs/PHONEGAP_BUILD.md +++ b/StoneIsland/plugins/phonegap-plugin-push/docs/PHONEGAP_BUILD.md @@ -4,20 +4,19 @@ - [Including the plugin](#including-the-plugin) - [Adding Resources](#adding-resources) - [IntelXDK Support](#intelxdk-support) -- [Ionic Cloud Build](#ionic-cloud-build) ## PhoneGap Build Support -> PhoneGap Build now support version 1.9.0 of the plugin. +> Currently PhoneGap Build does not support version 1.9.0 of the plugin. Updates are being made to PGB to support the latest release. ### Including the plugin -Including this plugin in a project that is built by PhoneGap Build is as easy as adding (replacing `123456789` with your own, that is): +Including this plugin in a project that is built by PhoneGap Build is as easy as adding: ```xml <preference name="android-build-tool" value="gradle" /> <plugin name="phonegap-plugin-push" source="npm"> - <param name="SENDER_ID" value="123456789" /> + <param name="SENDER_ID" value="<Your Sender ID>" /> </plugin> ``` @@ -92,25 +91,3 @@ f. you probably need to install the required gem (`gem install pushmeup`) g. send the notification (`ruby pushAPNS.rb`) 10. See notification on device! - -## Ionic Cloud Build - -Users have reported issues with Ionic Cloud Build. Apparently there are some differences in the way variables are handled. If your app has an issue where the `PushNotification` object can't be found try the following. - -1. Remove the inclusion of `phonegap-plugin-push` from config.xml. That is delete lines that look like this: - -``` -<plugin name="phonegap-plugin-push" spec="~1.9.1"> - <variable name="SENDER_ID" value="xxx"/> -</plugin> -``` -2. Add the following lines into `package.json` in the `cordovaPlugins` array. - -``` -{ - "variables": { - "SENDER_ID": "xxx" - }, - "locator": "phonegap-plugin-push" -} -``` diff --git a/StoneIsland/plugins/phonegap-plugin-push/docs/TYPESCRIPT.md b/StoneIsland/plugins/phonegap-plugin-push/docs/TYPESCRIPT.md index 53d215b3..37117d16 100644 --- a/StoneIsland/plugins/phonegap-plugin-push/docs/TYPESCRIPT.md +++ b/StoneIsland/plugins/phonegap-plugin-push/docs/TYPESCRIPT.md @@ -1,7 +1,7 @@ # Typescript definition file For those of you who use typescript, we're glad to say that we have the complete definition file available at [DefinitelyTyped](https://github.com/DefinitelyTyped/DefinitelyTyped). -Search for `phonegap-plugin-push` there, or simply grab it directly [here](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/types/phonegap-plugin-push/index.d.ts). +Search for `phonegap-plugin-push` there, or simply grab it directly [here](https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/phonegap-plugin-push/phonegap-plugin-push.d.ts). ## Example usage @@ -11,6 +11,7 @@ All available attributes and properties will have autocomplete support and type ```typescript let push = PushNotification.init({ android: { + senderID: "12345679" }, ios: { alert: "true", @@ -68,4 +69,4 @@ push.on('notification', (data: my.custom.NotificationEventResponse) => { ## Outdated definitions Is our definition file at DefinitelyTyped outdated? Is there any improvements that could be done? -We welcome any contribution, and they should be done through issues created [there](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/new). +We welcome any contribution, and they should be done through issues created [there](https://github.com/DefinitelyTyped/DefinitelyTyped/issues/new).
\ No newline at end of file |
