Phonegap Push Plugin
Last updated
Last updated
Deprecated
This Cordova plugin is used to register and receive push notifications.
Repository: https://github.com/phonegap/phonegap-plugin-push
Plugin ID/package name: phonegap-plugin-push
Tested version: 2.3.0
The custom build debugger can not check push notifications. To check push notifications, please check with a debug build or a release build.
Import the Phonegap push demo to your Monaca account
When working with push notifications for iOS, an APNs authentication key or an APNs certificate is required. This section will show you how to create a development APNs certificate for testing on an iOS debug build. For release build, a production APNs certificate is required.
In order to continue, you should have signed up to the Apple Developer Program. Follow the instructions below to create a development APNs certificate.
From the Apple Developer page, go to Account
.
Select Certificates, Identifiers & Profiles.
3. An app ID with push notifications enabled is required when creating an APNs certificate. Therefore, let’s create one. Under Identifiers
section, go to the App IDs
and click the ➕ button in the upper right corner.
4. Fill in the app ID information:
App Description
: Input your app name here (e.g. Cordova Firebase Demo)
Explicit ID
: Select this option because a Wildcard App ID is not allowed for push notifications. Input a unique identifier for your app (e.g. io.monaca.firebase).
5. Scroll down to the App Services
section and tick the Push Notifications option. Then, click Continue.
6. After that, you will be redirected to the Confirm your App ID
page. Click Register to complete the process.
7. Now, you should be back to the iOS App IDs page. Select the App ID you’ve just created and click Edit.
8. Scroll down to the Push Notifications
section, click Create Cerficate under Development SSL Certificate
.
9. Click Continue.
10. Click Choose File to browse your CSR file. You can get this file from the Monaca Cloud IDE by going to Config → iOS Build Settings. Then, click Generate Key and CSR. After creating the CRS file, download it by clicking the Export button.
11. Next, click Continue again. When the certificate is ready, you can download it. Save the file.
12. Upload the downloaded certificate by clicking the Upload Certificate button in the iOS Build Settings.
13. Click the Export icon of the target certificate displayed in the Certificates registered in Monaca to export the p12
file. You will need it for the Firebase configuration in the upcoming section.
Go to the Firebase Console.
Sign in with your Google account to enter the console.
Click Add project.
4. Fill in the project information and click CREATE PROJECT. Then, you will be redirected to the Project Overview
page.
After project creation, we can configure the push notification project for a specific platform.
Go to the Project settings
.
2. Under the General section, click ADD APP and select iOS.
3. Enter your iOS Bundle ID (You can find that by going to Config → iOS App Settings). Then, click REGISTER APP.
4. Download the GoogleService-Info.plist
file and place it in the root folder of your project. After that, click CONTINUE.
5. You will see the instructions on how to add the Firebase SDK to our project. However, we are not developing the app natively so we can skip this step. Just click CONTINUE to proceed. Then, click FINISH to complete the configuration. After that, you should see your iOS app in the Firebase overview page.
6. Now, it’s time to add the APNs certificates to the project. Go to the Project settings
and select CLOUD MESSAGING.
7. Scroll down to the iOS app configuration section and upload the APNs authentication key or APNs certificates.
That’s it! You are done with iOS configuration.
Go to Project settings
.
2. Under the General
section, click ADD APP and select Android.
3. Enter your package name (You can find that by going to Config → Android App Settings). Then, click REGISTER APP.
4. Download the google-services.json
file and place it in the root folder of your project. After that, click CONTINUE.
5. You will see instructions on how to add the Firebase SDK into our project. However, we are not developing the app natively so we can skip this step. Just click FINISH to complete the configuration. After that, you should see your Android app in the Firebase overview page.
From the IDE menu, go to Config → Manage Cordova Plugins .
Click the Import Cordova Plugin button. Then, you can choose to import the plugin using a ZIP file or a URL/package name.
After importing the plugin to the project, you can initialize the push notifications. Please make sure to call the plugin API after the Cordova is loaded. For example:
This section describes some of the main functions used in our demo. For complete API references, please refer to the repository.
Initialize push notifications.
Parameter
Name | Type | Description |
| Object | An object describing relevant specific options for all target platforms. |
All iOS Boolean
options can also be specified as String
.
Attribute | Type | Default | Description |
| Boolean |
| [optional] If set to |
| Boolean |
| [optional] If set to |
| Boolean |
| [optional] If set to |
| Boolean |
| [optional] If set to |
| Boolean |
| [optional] If set to |
| Object |
| [optional] The data required in order to enabled Action Buttons for iOS. See Action Buttons on iOS for more details. |
*
: Please note that the value you set this option to the first time you call the init method will be how the application always acts. Once this is set programmatically in the init method it can only be changed manually by the user in . This is normal iOS behaviour.
Attribute | Type | Default | Description |
| String | [Optional] The name of a drawable resource to use as the small-icon. The name should not include the extension. | |
| 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)) | |
| Boolean |
| [Optional] If set to |
| Boolean |
| [Optional] If set to |
| Boolean |
| [Optional] If set to |
| Boolean |
| [Optional] If set to |
| Boolean |
| [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. |
| Array |
| [Optional] If the array contains one or more strings each string will be used to subscribe to a FcmPubSub topic. |
| String |
| [Optional] The key to search for text of notification |
| String |
| [Optional] The key to search for title of notification |
Return Value
pushObject
Example
Check whether the push notification permission has been granted on the device.
Parameter
Name | Type | Description |
| Function | Is called when the api successfully retrieves the details on the permission. |
Callback Parameters
successHandler
Name | Type | Description |
| Boolean | Whether the permission for push notifications has been granted. |
Return Value
Promise
Example
Get the current badge count visible when the app is not running
Parameter
Name | Type | Description |
| Function | Is called when the api successfully retrieves the icon badge number. |
| Function | Is called when the api encounters an error while trying to retrieve the icon badge number. |
Callback Parameters
successHandler
Name | Type | Description |
| Number | An integer which is the current badge count |
Return Value
Promise
Example
Set the badge count visible when the app is not running.
Parameter
Name | Type | Description |
| Function | Is called when the api successfully retrieves the icon badge number. |
| Function | Is called when the api encounters an error while trying to retrieve the icon badge number. |
| Number | Indicates what number should show up in the badge. Passing |
Return Value
Promise
Example
The event notification
will be triggered each time a push notification is received by a 3rd party push service on the device.
Callback Parameters
Name | Type | Description |
| String | The text of the push message sent from the 3rd party service |
| String | [optional] The title of the push message sent from the 3rd party service |
| String | The number of messages to be displayed in the badge in iOS/Android or message count in the notification shade in Android. For windows, it represents the value in the badge notification which could be a number or a status glyph. |
| String | The name of the sound file to be played upon receipt of the notification |
| String | The path of the image file to be displayed in the notification |
| String | The args to be passed to the application on launch from push notification. This works when notification is received in background. (Windows Only) |
| Object | [optional] A collection of data sent by the 3rd party push service that does not fit in the above properties |
| Boolean | Whether the notification was received while the app was in the foreground |
| Boolean | Will be true if the application is started by clicking on the push notification, false if the app is already started. |
| Boolean | Is set to true if the notification was dismissed by the user |
Return Value
Promise
Example