SlideShare a Scribd company logo
1 of 4
Download to read offline
PhoneGap API (JavaScript)
Register and Unregister
Get device id
Handle incoming notifications
Tags
Boolean
Number
String
Date
Remove Tags
Register and Unregister
You can register a device to a remote notifications, only after the "deviceready" event was called. In order to register the device, all you need is
this line:
PushNotification.registerDevice(YOUR_GOOGLE_PROJECT_NUMBER, PUSHAPPS_APP_TOKEN,
function (pushToken) {
console.log("My push token: " + pushToken);
},
function (error) {
console.log(error);
});
For unregistering the device, just call:
PushNotification.unRegisterDevice(function () {
console.log("Success!");
},
function (error) {
console.log(error);
});
Get device id
PushApps uses a unique device id, in order to identify the device. If you would like to use the same id, you can call this method:
PushNotification.getDeviceId(function (deviceId) {
console.log("Your device ID: " + deviceId);
},
function (error) {
console.log(error);
});
A guide for obtaining the Google Project Number can be found here: Android Getting Started
If you're not supporting an Android platform, just pass an empty string instead of "YOUR_GOOGLE_PROJECT_NUMBER" (the first
parameter).
Handle Incoming Notifications
PushApps will raise an HTML event, every time an incoming notification is received. In order to bind a function to this event, all you need is:
document.addEventListener('pushapps.message-received', function(event) {
var notification = event.notification;
// This is the entire object, just take the wanted
propertey
console.log(notification);
});
Tags
There will be a time when you will want to send a push notification to a group of users, with a common characteristics. In order to do that, the
PushApps PhoneGap plugin gives you the ability to mark users with a specific tag. For example: one's age. You can add as many tags as you
want per user. For each, you'll need to supply the tag's identifier and the tag's value.
A set of tags and conditions between them creates a Segment, to learn more about Segments please refer to our Segmentation guide
There are 4 types of tags:
Boolean ( by a String , "true" or "false")
String
Number
Date
Boolean
// Add boolean tag
var bool = document.getElementById('myCheckbox').value === "on" ? "true" : "false";
var iden = "Vegetarian";
PushNotification.setTags([{
identifier: iden,
value: bool
}], function () {
alert("Your tag was successfully added");
}, function (message) {
alert("ERROR: " + message);
});
Number
// Add number tag
var number = document.getElementById("myNumberInput").value;
var iden = "Age";
PushNotification.setTags([{
identifier: iden,
value: number
}], function () {
alert("Your tag was successfully added");
}, function (message) {
alert("ERROR: " + message);
});
String
// Add string tag
var str = document.getElementById("cityNameInput").value;
var iden = "City";
PushNotification.setTags([{
identifier: iden,
value: str
}], function () {
alert("Your tag was successfully added");
}, function (message) {
alert("ERROR: " + message);
});
Date
// Add date tag
var d = new Date(document.getElementById("birthdayInput").value);
var date = d.toISOString();
var iden = "Birthday";
PushNotification.setTags([{
identifier: iden,
value: date
}], function () {
alert("Your tag was successfully added");
}, function (message) {
alert("ERROR: " + message);
});
Remove Tags
You can always remove tags from user, by calling the removeTags function:
// Remove tags
var idens = [ "Age", "Birthday", "City" ];
PushNotification.removeTags(idens, function () {
alert("Tags removed successfully");
}, function (message) {
alert("ERROR: " + message);
});

More Related Content

Viewers also liked

Hongkong Disney Land Hotel
Hongkong Disney Land HotelHongkong Disney Land Hotel
Hongkong Disney Land Hotel
katrineerika
 
How to create android push notifications with custom view
How to create android push notifications with custom viewHow to create android push notifications with custom view
How to create android push notifications with custom view
PushApps - Content Recommendation in Push Notifications
 
Sistem Pengukuran Kompresi Mesin
Sistem Pengukuran Kompresi MesinSistem Pengukuran Kompresi Mesin
Sistem Pengukuran Kompresi Mesin
Joel TambarMalem
 

Viewers also liked (6)

Arctic animals
Arctic animalsArctic animals
Arctic animals
 
Hongkong Disney Land Hotel
Hongkong Disney Land HotelHongkong Disney Land Hotel
Hongkong Disney Land Hotel
 
How to create android push notifications with custom view
How to create android push notifications with custom viewHow to create android push notifications with custom view
How to create android push notifications with custom view
 
8 planets in the solar system
8 planets in the solar system8 planets in the solar system
8 planets in the solar system
 
Sistem Pengukuran Kompresi Mesin
Sistem Pengukuran Kompresi MesinSistem Pengukuran Kompresi Mesin
Sistem Pengukuran Kompresi Mesin
 
Parts of eyes
Parts of eyesParts of eyes
Parts of eyes
 

Recently uploaded

Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
jaanualu31
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 

Recently uploaded (20)

data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Air Compressor reciprocating single stage
Air Compressor reciprocating single stageAir Compressor reciprocating single stage
Air Compressor reciprocating single stage
 
Bridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptxBridge Jacking Design Sample Calculation.pptx
Bridge Jacking Design Sample Calculation.pptx
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
AIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech studentsAIRCANVAS[1].pdf mini project for btech students
AIRCANVAS[1].pdf mini project for btech students
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
Engineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planesEngineering Drawing focus on projection of planes
Engineering Drawing focus on projection of planes
 
Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086Minimum and Maximum Modes of microprocessor 8086
Minimum and Maximum Modes of microprocessor 8086
 
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptxHOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
HOA1&2 - Module 3 - PREHISTORCI ARCHITECTURE OF KERALA.pptx
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 

PhoneGap Push Notifications API (JavaScript)

  • 1. PhoneGap API (JavaScript) Register and Unregister Get device id Handle incoming notifications Tags Boolean Number String Date Remove Tags Register and Unregister You can register a device to a remote notifications, only after the "deviceready" event was called. In order to register the device, all you need is this line: PushNotification.registerDevice(YOUR_GOOGLE_PROJECT_NUMBER, PUSHAPPS_APP_TOKEN, function (pushToken) { console.log("My push token: " + pushToken); }, function (error) { console.log(error); }); For unregistering the device, just call: PushNotification.unRegisterDevice(function () { console.log("Success!"); }, function (error) { console.log(error); }); Get device id PushApps uses a unique device id, in order to identify the device. If you would like to use the same id, you can call this method: PushNotification.getDeviceId(function (deviceId) { console.log("Your device ID: " + deviceId); }, function (error) { console.log(error); }); A guide for obtaining the Google Project Number can be found here: Android Getting Started If you're not supporting an Android platform, just pass an empty string instead of "YOUR_GOOGLE_PROJECT_NUMBER" (the first parameter).
  • 2. Handle Incoming Notifications PushApps will raise an HTML event, every time an incoming notification is received. In order to bind a function to this event, all you need is: document.addEventListener('pushapps.message-received', function(event) { var notification = event.notification; // This is the entire object, just take the wanted propertey console.log(notification); }); Tags There will be a time when you will want to send a push notification to a group of users, with a common characteristics. In order to do that, the PushApps PhoneGap plugin gives you the ability to mark users with a specific tag. For example: one's age. You can add as many tags as you want per user. For each, you'll need to supply the tag's identifier and the tag's value. A set of tags and conditions between them creates a Segment, to learn more about Segments please refer to our Segmentation guide There are 4 types of tags: Boolean ( by a String , "true" or "false") String Number Date Boolean // Add boolean tag var bool = document.getElementById('myCheckbox').value === "on" ? "true" : "false"; var iden = "Vegetarian"; PushNotification.setTags([{ identifier: iden, value: bool }], function () { alert("Your tag was successfully added"); }, function (message) { alert("ERROR: " + message); }); Number
  • 3. // Add number tag var number = document.getElementById("myNumberInput").value; var iden = "Age"; PushNotification.setTags([{ identifier: iden, value: number }], function () { alert("Your tag was successfully added"); }, function (message) { alert("ERROR: " + message); }); String // Add string tag var str = document.getElementById("cityNameInput").value; var iden = "City"; PushNotification.setTags([{ identifier: iden, value: str }], function () { alert("Your tag was successfully added"); }, function (message) { alert("ERROR: " + message); }); Date // Add date tag var d = new Date(document.getElementById("birthdayInput").value); var date = d.toISOString(); var iden = "Birthday"; PushNotification.setTags([{ identifier: iden, value: date }], function () { alert("Your tag was successfully added"); }, function (message) { alert("ERROR: " + message); }); Remove Tags You can always remove tags from user, by calling the removeTags function:
  • 4. // Remove tags var idens = [ "Age", "Birthday", "City" ]; PushNotification.removeTags(idens, function () { alert("Tags removed successfully"); }, function (message) { alert("ERROR: " + message); });