new Push()
This is a global variable called push exposed by cordova
- Source:
Methods
-
register(onNotification, successCallback, errorCallback, options) → {void}
-
Registers the device with the APNS (iOS) or GCM (Android) and the Unified Push server.
Parameters:
Name Type Argument Description onNotification
function callback to be executed if a message arrives successCallback
function callback to be executed when register is succesful errorCallback
function <optional>
callback to be executed if the request results in error options
Object <optional>
A configuration for the Unified Push server, so that it can register this device. This is optional a when a file called push-config.json is put in the `www` folder this will be used. The object can have the following properties: Properties
Name Type Argument Description senderId
String <optional>
android specific - the id representing the Google project ID variantID
String the id representing the mobile application variant variantSecret
String the secret for the mobile application variant pushServerURL
String the location of the UnifiedPush server e.g. http(s)//host:port/context alias
String <optional>
Application specific alias to identify users with the system. Common use case would be an email address or a username. ios
Object <optional>
Holder of the ios specific values variantID and variantSecret Properties
Name Type Argument Description variantID
String <optional>
the id representing the mobile application variant for iOS variantSecret
String <optional>
the secret for the mobile application variant for iOS android
Object <optional>
Holder of the android specific values variantID and variantSecret Properties
Name Type Argument Description variantID
String <optional>
the id representing the mobile application variant for android variantSecret
String <optional>
the secret for the mobile application variant for android - Source:
Returns:
- Type
- void
Examples
var pushConfig = { pushServerURL: "<pushServerURL e.g http(s)//host:port/context >", senderID: "<senderID e.g Google Project ID>", variantID: "<variantID e.g. 1234456-234320>", variantSecret: "<variantSecret e.g. 1234456-234320>" alias: "<alias e.g. a username or an email address optional>", } push.register(onNotification, successHandler, errorHandler, pushConfig);
//combined android and ios configuration var pushConfig = { pushServerURL: "<pushServerURL e.g http(s)//host:port/context >", alias: "<alias e.g. a username or an email address optional>", android: { senderID: "<senderID e.g Google Project ID>", variantID: "<variantID e.g. 1234456-234320>", variantSecret: "<variantSecret e.g. 1234456-234320>" }, ios: { variantID: "<variantID e.g. 1234456-234320>", variantSecret: "<variantSecret e.g. 1234456-234320>" } }; push.register(onNotification, successHandler, errorHandler, pushConfig);
//push-config.json file in www folder { "pushServerURL": "<pushServerURL e.g http(s)//host:port/context >", "android": { "senderID": "<senderID e.g Google Project ID only for android>", "variantID": "<variantID e.g. 1234456-234320>", "variantSecret": "<variantSecret e.g. 1234456-234320>" }, "ios": { "variantID": "<variantID e.g. 1234456-234320>", "variantSecret": "<variantSecret e.g. 1234456-234320>" } } push.register(onNotification, successHandler);
-
setApplicationIconBadgeNumber(success, badge) → {void}
-
Call this to set the application icon badge -- ios specific
Parameters:
Name Type Argument Description success
function callback to be executed if the request results in success badge
String | Number <optional>
the badge number to set on the application icon - Source:
Returns:
- Type
- void
Example
push.setApplicationIconBadgeNumber(successHandler, errorHandler);
-
setContentAvailable(dataType) → {void}
-
Call this function to tell the OS if there was data or not so it can schedule the next fetch operation
Parameters:
Name Type Description dataType
int one of the BackgroundFetchResults or 0 new data 1 no data or 2 failed - Source:
Returns:
- Type
- void
-
unregister(success, error) → {void}
-
Unregisters the device with the APNS (iOS) or GCM (Android) and the Unified Push server.
Parameters:
Name Type Argument Description success
function callback to be executed if the request results in success error
function <optional>
callback to be executed if the request results in error - Source:
Returns:
- Type
- void
Example
push.unregister(successHandler, errorHandler);