Coder Social home page Coder Social logo

cordova-plugin-game-center's Introduction

Game Center Plugin for Apache Cordova npm version

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.

Live demo

See this plugin working in a live app: playadds.com

Before you start

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.

Install

Latest published version on npm (with Cordova CLI >= 5.0.0)

cordova plugin add cordova-plugin-game-center

Latest version from GitHub

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.

PhoneGap build

Add the following to your config.xml to use version 0.4.1 (you can also omit the version attribute to always use the latest version). You should now use the npm source:

<gap:plugin name="cordova-plugin-game-center" version="0.4.1" source="npm" />

For more information, see the PhoneGap build docs.

Usage

Auth

You should do this as soon as your deviceready event has been fired. The plug handles the various auth scenarios for you.

var successCallback = function (user) {
    alert(user.alias);
    // user.alias, user.playerID, user.displayName
};

gamecenter.auth(successCallback, failureCallback);

Fetch Player Image

Loads the current player's photo. Automatically cached on first retrieval.

var successCallback = function (path) {
    alert(path); // path to .jpg
};

gamecenter.getPlayerImage(successCallback, failureCallback);

Submit Score

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);

Show leaderboard

Launches the native Game Center leaderboard view controller for a leaderboard.

var data = {
    leaderboardId: "board1"
};
gamecenter.showLeaderboard(successCallback, failureCallback, data);

NB: The period option has been removed in 0.3.0 as it is no longer supported by iOS. The default period is "all time".

Report achievement

Reports an achievement to the game center:

var data = {
	achievementId: "MyAchievementName",
	percent: "100"
};

gamecenter.reportAchievement(successCallback, failureCallback, data);

Reset achievements

Resets the user's achievements and leaderboard.

gamecenter.resetAchievements(successCallback, failureCallback);

Fetch achievements

Fetches the user's achievements from the game center:

var successCallback = function (results) {
	if (results) {
    	for (var i = 0; i < results.length; i += 1) {
            //results[i].identifier
            //results[i].percentComplete
            //results[i].completed
            //results[i].lastReportedDate
            //results[i].showsCompletionBanner
            //results[i].playerID
        }
    }
}

gamecenter.getAchievements(successCallback, failureCallback);

Platforms

Supports iOS 7 and iOS 8 (may have limited iOS 6 support). The Game Center is Apple specific and not applicable to other platforms.

Please report any issues.

License

MIT License

cordova-plugin-game-center's People

Contributors

dnsmob avatar leecrossley avatar mulhoon avatar rocklan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-game-center's Issues

Display all achievements

Hi,
the function getAchievements() only return me completed achievements.
How can I get all the achievements even if they are not completed ?
Thanks a lot.

How to auth?

var successCallback = function (user) {
alert(user.alias);
// user.alias, user.playerID, user.displayName
};

gamecenter.auth(successCallback, failureCallback);

Do we uncomment //user.alias, user.playerID, user.displayName?
And do we replace the playerID/displayName/alias with something?

Leaderboards does not shown?

Hi there,
Thanks you very much for this plugin.
I'm able to display the Leaderboard screen, however, i didn't see any score on that board (it says: No Leaderboard), though i've submitted a couple of scores using different test accounts.

this.reportTimeToGameCenter = function(time) {
    var data = {
      score: time,
      leaderboardId: "xxx-xxx-xx"
    };
    if (window.gamecenter) {
      window.gamecenter.submitScore(function() {
        console.log("### Submit score success");
      }, function(message) {
        console.log("### Submit score error");
        console.log(message)
      }, data);
    }
  };

The code say "Submit score success".

Any help would be highly appreciate!

Leaderboard Set ID ignored in showLeaderboard method

maybe this is by design, but if instead of the Leaderboard ID you specify the Leaderboardset ID (many games have a main board which is divided in different leaderboards per game mode difficulty), the view shows you the first sub set of the Leaderboard set instead of the main Leaderboard set view. And the user needs to manually navigate to the main menu.

To make it more clear:
If you have a game that consists of 3 Levels of difficulty, "Easy", "Medium", "Hard" and you have created one leaderboard for each level and all 3 leaderboards are part of your Leaderboard Set, then currently there is no way to load the main generic board by submitting the Leaderboard Set Id. I tried but it failed.

This is not a top matter, but it would be nice to be able to load the main Leaderboard Set instead of forcing them to view the first sub set("Easy" leaderboard in our case)

Just a thought - maybe you could add, a showLeaderboardSet method or extend the existing method

GameCenter plugin and AngularJS + Ionic

Hy there,

could not make it work on AngularJS and Ionic.

I'm always getting this message:

  • D/PluginManager(2836): exec() call to unknown plugin: GameCenter

Installed using cordova plugin add, and included the call on read for ionic

app.run(function($rootScope, $ionicLoading,$ionicPopup,$ionicPlatform) {
    var failureLoginCallback = function (user) {
        console.log("ERRROOOO failureCallback");
        console.log(user);
    };

    var successLoginCallback = function (user) {
        console.log("SUCESSO LOGIN");
        alert(user.alias);
        // user.alias, user.playerID, user.displayName
    };

    $ionicPlatform.ready(function() {

        gamecenter.auth(successLoginCallback, failureLoginCallback);

    });

Any ideas?

Cant report achievement

I have added the plugin and call the authenticate methods. This works and signs me in as expected.

If I check the game center app, my app is recognised and the list of achievements is displayed from gamecenter servers.

However if i call reportAchievement nothing updates in game center.

I get the success call back from the plugin and the banner displays but game center never registers the achievement as being complete.

The bundleid in config.xml matches the one in itunes connect and the achievement id matches as well.
I am using phonegapbuild if that makes a difference?
Not sure what is going on here.

playerID deprecated warning iOS 8

/hello/platforms/ios/HelloWorld/Plugins/uk.co.ilee.gamecenter/GameCenter.m:250:51: 'playerID' is deprecated: first deprecated in iOS 8.0 - use player

Is there a fix for this?

It doesn't do anything

Hi so I've tried this many times and put the javascript in the ondevice ready function and it doesn't do anything. Game center doesn't load at the begining I'm not getting any errors or anything I'm just not seeing anything. can you think of what would cause it to seemessly skip over the gamecenter part. I'm building for 7.1

Multiplayer support?

What would be the impact to add support for the Game Center Multiplayer APIs, i.e. Matchmaking / networking?

Can't compile on Cordova 5.1.1

Hi Lee,

i was trying to use your plugin but it fails on compile. Any idea? Can't use it at all

Instaling...

➜ ~/dev/proyectotest/ipa (master) cordova plugin add https://github.com/leecrossley/cordova-plugin-game-center.git

Fetching plugin "https://github.com/leecrossley/cordova-plugin-game-center.git" via git clone
Repository "https://github.com/leecrossley/cordova-plugin-game-center.git" checked out to git ref "master".
Installing "cordova-plugin-game-center" for ios

Building..

➜ ~/dev/proyectotest/ipa (master) cordova build --release
...
ker -dependency_info -Xlinker /Users/rotoxl/dev/proyectotest/ipa/platforms/ios/build/Octopus.build/Release-iphonesimulator/Octopus.build/Objects-normal/i386/Octopus_dependency_info.dat -o /Users/rotoxl/dev/proyectotest/ipa/platforms/ios/build/emulator/Octopus.app/Octopus
Undefined symbols for architecture i386:
  "_OBJC_CLASS_$_GKAchievement", referenced from:
      objc-class-ref in GameCenter.o
  "_OBJC_CLASS_$_GKGameCenterViewController", referenced from:
      objc-class-ref in GameCenter.o
  "_OBJC_CLASS_$_GKLocalPlayer", referenced from:
      objc-class-ref in GameCenter.o
  "_OBJC_CLASS_$_GKNotificationBanner", referenced from:
      objc-class-ref in GameCenter.o
  "_OBJC_CLASS_$_GKScore", referenced from:
      objc-class-ref in GameCenter.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

** BUILD FAILED **


The following build commands failed:
    Ld build/emulator/Octopus.app/Octopus normal i386
(1 failure)
Error code 65 for command: xcodebuild with args: -xcconfig,/Users/rotoxl/dev/proyectotest/ipa/platforms/ios/cordova/build-release.xcconfig,-project,Octopus.xcodeproj,ARCHS=i386,-target,Octopus,-configuration,Release,-sdk,iphonesimulator,build,VALID_ARCHS=i386,CONFIGURATION_BUILD_DIR=/Users/rotoxl/dev/proyectotest/ipa/platforms/ios/build/emulator,SHARED_PRECOMPS_DIR=/Users/rotoxl/dev/proyectotest/ipa/platforms/ios/build/sharedpch
ERROR building one of the platforms: Error: /Users/rotoxl/dev/proyectotest/ipa/platforms/ios/cordova/build: Command failed with exit code 2
You may not have the required environment or OS to build this project
Error: /Users/rotoxl/dev/proyectotest/ipa/platforms/ios/cordova/build: Command failed with exit code 2
    at ChildProcess.whenDone (/Users/rotoxl/.nvm/v0.10.32/lib/node_modules/cordova/node_modules/cordova-lib/src/cordova/superspawn.js:134:23)
    at ChildProcess.emit (events.js:98:17)
    at maybeClose (child_process.js:756:16)
    at Process.ChildProcess._handle.onexit (child_process.js:823:5)

My cordova version is

➜ ~/dev/proyectotest/ipa (master) cordova -v
5.1.1

Thank you

gamecenter.getAchievements

I've been trying to use the getAchievements function, but not having any luck.
I've stripped back to just trying to get a success or error call, but still no joy.

gamecenter.getAchievements(function(){ navigator.notification.alert("gc success"); }, function(){ navigator.notification.alert("gc fail"); });

Also I've noticed that the readme lists the getAchievements function as reportAchievement.

Also tried applying this fix (39641d6), but it doesn't seem to have patched the problem.

Love the plugin, and hope you can find a fix. If I can get anything working myself, I'll submit.

Thanks

Question: Matchmaking support?

This is more of a question than a bug report or feature request:

As far as I'm aware, all the Cordova Game Center plugins I've come across have no support for match making, a feature of Game Center. I'm building a multiplayer mobile game using Ionic, which makes use of Cordova and its array of plugins. I'd like to utilize Game Center's matchmaking capabilities, but it's starting to look like I may have to learn obj C and build my own plugin and/or fork an existing one.

So my question: what are the main reasons you (and others) have left out match making support from the plugin API? Is it even possible to do matchmaking with Cordova, or would I just need to build a native (not hybrid) app in Obj C/Swift?

Retrieving Scores from Game Center

Hi
Is there a way to retrieve the scores and ranking from the Game Center leaderboard in order to implement a custom Leaderboard UI?
Cheers

Posting an achievement on iOS8 shows 2 messages

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
    [GKNotificationBanner showBannerWithTitle:@"Achievement" message:@"Completed!" completionHandler:^{}];
}

This code in GameCenter.m causes 2 achievement messages to be shown to the user on iOS8 when posting an achievement. I suggest to update or remove this code as iOS8 is on many devices already.

"Plugin should use a background thread."

In Xcode log it says:
THREAD WARNING: ['GameCenter'] took '26.479980' ms. Plugin should use a background thread.

Also on some iPhone models, logging in game center takes a while and affects UI. How can I make it use a background thread? Or is there such a feature in the plugin?

screen is white

So the issue I'm having is that when the app loads it never gets past this all white screen. I've only tested it in an ios simulator as I don't actualy have an iphone. In xcode all of the steps to get gamecenter to work are checked off. I've completely redone the whole process many times and get the same result every time. any ideas?

The callback functions are not called after auth

Hi there,

The plugin works like a charm in practice so huge thanks first of all. However, the callback functions after auth() are not called for some reason. I am using ionic and testing it on an iPhone 7 device.

I can see the game center welcome screen once the auth() is called and I can also display the leadersboard, submit score etc. however, the callbacks are not fired for some reason.

As I cannot confirm if the auth has been successful, I am not sure when/whether to call showLeaderboard()

Many thanks in advance for your guidance on the issue.

Cheers,

Doug

onPluginsReady error

Plugin loading seems broken:
[Log] deviceready has not fired after 5 seconds. (cordova.js, line 1143)
[Log] Channel not fired: onPluginsReady (cordova.js, line 1136)
[Log] Channel not fired: onCordovaReady (cordova.js, line 1136)

schermata 2014-10-19 alle 12 23 34

I also tried to use this plugin alone (Without any other plugin) and the error is the same.

Config.xml has:


cordova_plugins.js has:
{
"file": "plugins/gamecenter/www/gamecenter.js",
"id": "uk.co.ilee.gamecenter.GameCenter",
"clobbers": [
"gamecenter"
]
}

and:
"uk.co.ilee.gamecenter": "0.2.9"

Index.js, the main app initializer has, after DeviceReady:
app.receivedEvent("deviceready");
var successCallback = function (user) {
alert(user.alias);
// user.alias, user.playerID, user.displayName
};

gamecenter.auth(successCallback, failureCallback);

Other plugins like "Social Sharing" and "iAd" are correctly working.

Test environment:
iOS8 (iPhone) / iOS7.1.1 (iPad)
iPhone5, iPad2 and Simulator
OSX 10.9.5
cordova 3.5.0-0.2.7

Achievement message displayed wrongly on iOS7

Thank you Lee for the quick fix of #25.

I have found another related issue with posting an achievement. When you post an achievement on iOS7 the "Achievement completed" message is also shown when the percentage is not 100%. My app currently shows an endless loop of completed messages, when in reality the achievement is not completed yet.

I suggest to only show this message when the given percentage is 100.

Offline

This is a fantastic plugin, and worked first time for me, so thanks for making my life infinitely easier. I'm struggling with handling an offline scenario though - am I right in thinking that neither Game Center nor this plugin automatically handle caching etc. if the device is offline during auth() and submitScore() calls?

Get game center user nickname?

This is a great plugin!

I just was wondering...
Is it possible to retrieve the user's nickname from the game center?
This would be extremely useful for me. Sorry if this is not the best place to ask this.

submitScore Success and Error callbacks are never triggered.

The plugin works like a charm except for the fact that the callback events when a score is submitted are never triggered.
The score is submitted but it would nice to know if the score has been submitted for sure or not.

I tested your plugin both on XCode iOS 7 and iOS 6 emulators as well as on an iPhone 4 device on iOS 7.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.