cordova plugin add https://github.com/thetypingpuppy/ezleaderboard.git --variable PLAY_APP_ID=123456789012
Add the paths to the ezleaderboard class. In your index.html (or any other relevant html files), add the following to the <head>
tag area.
<script type="text/javascript" src="plugins/ezleaderboard/ezleaderboard.js"></script>
First step is initialisation of the ezleaderboard class.
function onDeviceReady() {
var ezl = new ezleaderboard();
}
For iOS Game Center needs authorising. Best do this in onDeviceReady.
function onDeviceReady() {
if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)){
ezl.auth(successCallback(), errorCallback());
}
function successCallback(){
console.log("iOS Game centre authorised.");
}
function errorCallback(){
console.log("Game centre authorisation error.");
}
}
The argument array is a single entry array composed of one object. The object must contain the key: score
for both iOS and Android. Specifically for iOS the leaderboardID
key needs to be given as well.
function addScore(){
var args = [{score: 100, leaderboardID_ios: "ios_leaderboard_id", leaderboardID_droid: "droid_leaderboard_id"}];
ezl.submitToLeaderboard(successCallback, errorCallback, args);
}
On android the leaderboard in Game Play Services app will load automatically, in iOS it needs to be shown manually.
function addScore(){
var args = [{score: 100, leaderboardID_ios: "ios_leaderboard_id", leaderboardID_droid: "droid_leaderboard_id"}];
ezl.submitToLeaderboard(successCallback(), errorCallback(), args);
function successCallback(){
// If iOS show leaderboard
if (/(ipod|iphone|ipad)/i.test(navigator.userAgent)){
var args = [{leaderboardID_ios: "ios_leaderboard_id", showAchievements: "false"}];
ezl.showLeaderboard(function(){console.log("iOS Game centre leaderboard loaded.")}, function(){"Game centre leaderboard failed to load."}, args);
}
}
function errorCallback(){
console.log("Game centre score submission error.");
}
}