Skip to content

sergifern/phonegap

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

95 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phonegap/Cordova Plugin for Pushbots

PushBots' official module for Phonegap/Cordova

https://pushbots.com/developer/docs/phonegap-sdk-integration

Installation

This requires phonegap/cordova CLI 5.0+

cordova plugin add pushbots-cordova-plugin

##Usage

  1. Intialize Pushbots in deviceReady section:
window.plugins.PushbotsPlugin.initialize("PUSHBOTS_APPLICATIONID", {"android":{"sender_id":"SENDER_ID"}});

// Only with First time registration
// This will be called on token registration/refresh with Android and with every runtime with iOS
window.plugins.PushbotsPlugin.on("registered", function(token){
	console.log("Registration Id:" + token);
});

//Get user registrationId/token and userId on PushBots
window.plugins.PushbotsPlugin.on("user:ids", function(data){
	console.log("user:ids" + JSON.stringify(data));
});
  1. Methods to use it:
window.plugins.PushbotsPlugin.setAlias("Test");
window.plugins.PushbotsPlugin.removeAlias();

//Add or remove Single tag
window.plugins.PushbotsPlugin.tag("tag1");
window.plugins.PushbotsPlugin.untag("tag1");

//Add or remove array of tags
window.plugins.PushbotsPlugin.setTags(["tag1"]);
window.plugins.PushbotsPlugin.removeTags(["tag1"]);

window.plugins.PushbotsPlugin.debug(true);

//unsubscribe user from receiving notifications
window.plugins.PushbotsPlugin.toggleNotifications(false);

//iOS only

//Reset Badge
window.plugins.PushbotsPlugin.resetBadge();
//Set badge
window.plugins.PushbotsPlugin.setBadge(10);
//Increment badge count
window.plugins.PushbotsPlugin.incrementBadgeCountBy(1);
//Decrement badge count
window.plugins.PushbotsPlugin.decrementBadgeCountBy(10);
  1. To handle Notification events:
// Should be called once app receive the notification only while the application is open or in background
window.plugins.PushbotsPlugin.on("notification:received", function(data){
	console.log("received:" + JSON.stringify(data));
	
	//Silent notifications Only [iOS only]
	//Send CompletionHandler signal with PushBots notification Id
	window.plugins.PushbotsPlugin.done(data.pb_n_id);
});

// Should be called once the notification is clicked
window.plugins.PushbotsPlugin.on("notification:clicked", function(data){
	// var userToken = data.token; 
       // var userId = data.userId;
  	console.log("clicked:" + JSON.stringify(data));
});

##Phonegap build

add Pushbots plugin to config.xml:

<gap:plugin name="pushbots-cordova-plugin" spec="^1.4.5" source="npm" />
<preference name="phonegap-version" value="cli-6.3.0" />
<preference name="android-build-tool" value="gradle" />

Releases

No releases published

Packages

No packages published

Languages

  • Objective-C 59.3%
  • Java 25.0%
  • JavaScript 15.7%