This plugin allows developers to utilise the iOS Game Center in their Cordova / PhoneGap app.
The code under active development and currently has support for auth, submitting a score and showing leaderboards using the native viewcontroller.
See this plugin working in a live app: http://playadds.com
Adding Game Center support requires more than simple coding changes. To create a Game Center-aware game, you need to understand these basics before you begin writing code. The full outline of all the Game Center concepts and impacts can be viewed here.
cordova plugin add https://github.com/leecrossley/cordova-plugin-game-center.git
You do not need to reference any JavaScript, the Cordova plugin architecture will add a gamecenter object to your root automatically when you build. It will also automatically add the GameKit framework dependency.
You should do this as soon as your deviceready event has been fired. The plug handles the various auth scenarios for you.
gamecenter.auth(successCallback, failureCallback);
Ensure you have had a successful callback from gamecenter.auth()
first before attempting to submit a score. You should also have set up your leaderboard(s) in iTunes connect and use the leaderboard identifier assigned there as the leaderboardId.
var data = {
score: 10,
leaderboardId: "board1"
};
gamecenter.submitScore(successCallback, failureCallback, data);
Launches the native Game Center leaderboard view controller for a given period and leaderboard.
var data = {
period: "today",
leaderboardId: "board1"
};
gamecenter.showLeaderboard(successCallback, failureCallback, data);
The period options are "today", "week" or "all".
Reports an achievement to the game center:
var data = {
achievementId: "MyAchievementName",
percent: "100"
};
gamecenter.reportAchievement(successCallback, failureCallback, data);
Resets the user's achievements and leaderboard.
gamecenter.resetAchievement(successCallback, failureCallback);
Fetches the user's achievements from the game center:
var data = { };
gamecenter.reportAchievement(successCallback, failureCallback, data);
var successCallback = function(result) {
if (results) {
for (var i=0;i<results.length;i++) {
alert('Achievement earnt: " + results[i]);
}
}
}
Supports iOS 6 and iOS 7 (there are differences in the native implementation). The Game Center is Apple specific and not applicable to other platforms.
Achievements functionality only tested on IOS7.