Ionic Framework 4 is almost here. Preview the beta docs and try it out now! Try Ionic 4 Beta

Google Play Games Services

Improve this doc

A Cordova plugin that let's you interact with Google Play Games Services.

Repo: https://github.com/artberri/cordova-plugin-play-games-services

Installation

  1. Install the Cordova and Ionic Native plugins:
    $ ionic cordova plugin add cordova-plugin-play-games-services --variable APP_ID="YOUR_APP_ID
    $ npm install --save @ionic-native/google-play-games-services
    
  2. Add this plugin to your app's module

Supported platforms

Usage

import { GooglePlayGamesServices } from '@ionic-native/google-play-games-services';


constructor(private googlePlayGamesServices: GooglePlayGamesServices) { }

...

// Authenticate with Play Games Services
this.googlePlayGamesServices.auth()
    .then(() => console.log('Logged in to Play Games Services'))
    .catch(e) => console.log('Error logging in Play Games Services', e);

// Sign out of Play Games Services.
this.googlePlayGamesServices.signOut()
    .then(() => console.log('Logged out of Play Games Services'))
    .catch(e => console.log('Error logging out of Play Games Services', e);

// Check auth status.
this.googlePlayGamesServices.isSignedIn()
    .then((signedIn: SignedInResponse) => {
        if (signedIn.isSignedIn) {
            hideLoginButton();
        }
    });

// Fetch currently authenticated user's data.
this.googlePlayGamesServices.showPlayer().then((data: Player) => {
   console.log('Player data', data);
});

// Submit a score.
this.googlePlayGamesServices.submitScore({
    score: 100,
    leaderboardId: 'SomeLeaderboardId'
});

// Show the native leaderboards window.
this.googlePlayGamesServices.showAllLeaderboards()
    .then(() => console.log('The leaderboard window is visible.'));

// Show a signle native leaderboard window.
this.googlePlayGamesServices.showLeaderboard({
    leaderboardId: 'SomeLeaderBoardId'
}).then(() => console.log('The leaderboard window is visible.'));

// Unlock an achievement.
this.googlePlayGamesServices.unlockAchievement({
    achievementId: 'SomeAchievementId'
}).then(() => console.log('Achievement unlocked'));

// Incremement an achievement.
this.googlePlayGamesServices.incrementAchievement({
    step: 1,
    achievementId: 'SomeAchievementId'
}).then(() => console.log('Achievement incremented'));

// Show the native achievements window.
this.googlePlayGamesServices.showAchivements()
   .then(() => console.log('The achievements window is visible.'));

Instance Members

auth()

Initialise native Play Games Service login procedure.

Returns: Promise<any> Returns a promise that resolves when the player is authenticated with Play Games Services.

signOut()

Sign out of Google Play Games Services.

Returns: Promise<any> Returns a promise that resolve when the player successfully signs out.

isSignedIn()

Check if the user is signed in.

Returns: Promise<SignedInResponse> Returns a promise that resolves with the signed in response.

showPlayer()

Show the currently authenticated player.

Returns: Promise<Player> Returns a promise that resolves when Play Games Services returns the authenticated player.

submitScore(data)

Submit a score to a leaderboard. You should ensure that you have a successful return from auth() before submitting a score.

Param Type Details
data ScoreData

The score data you want to submit.

Returns: Promise<any> Returns a promise that resolves when the score is submitted.

showAllLeaderboards()

Launches the native Play Games leaderboard view controller to show all the leaderboards.

Returns: Promise<any> Returns a promise that resolves when the native leaderboards window opens.

showLeaderboard(data)

Launches the native Play Games leaderboard view controll to show the specified leaderboard.

Param Type Details
data LeaderboardData

The leaderboard you want to show.

Returns: Promise<any> Returns a promise that resolves when the native leaderboard window opens.

unlockAchievement(data)

Unlock an achievement.

Param Type Details
data AchievementData

Returns: Promise<any> Returns a promise that resolves when the achievement is unlocked.

incrementAchievement(data)

Increment an achievement.

Param Type Details
data IncrementableAchievementData

Returns: Promise<any> Returns a promise that resolves when the achievement is incremented.

showAchievements()

Lauches the native Play Games achievements view controller to show achievements.

Returns: Promise<any> Returns a promise that resolves when the achievement window opens.

API

Native

General