npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-game-center

v1.2.3

Published

Apple's Game Center integration with React Native

Downloads

25

Readme

React Native Game Center

Contents

Getting Started

  • Install react-native first
npm i react-native -g
react-native init myApp
cd myApp
yarn add react-native-game-center
react-native link
react-native run-ios

Basic Usage

  • In your index.js, use:
import RNGameCenter from "react-native-game-center"

RNGameCenter.getPlayer().then(player=>console.log("player: ",player))

Installation

  • From project root
yarn add react-native-game-center
react-native link
react-native run-ios

then Follow setup Instructions

Set Up

See SETUP.md

Example

or clone the repo and play with the example project

$ git clone https://github.com/garrettmac/react-native-game-center
$ cd react-native-game-center/GameCenterExample
$ yarn install
$ npm start

Init Method

init() <Promise?>

Details

Initiates your app with Game Center. Add this to the top of your app before your AppRegister.

ITUNES CONNECT APP DASHBOARD

https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa/ra/ng/app

Then

SELECT APP > Feature > Game Center

Parameters

| Name | Required | Default | Description | |--------------|--------------|--------------|--------------| | leaderboardIdentifier | Yes | undefined | Your apps default leaderboard Identifier. You can can several of these but at least one is required. | | achievementIdentifier | No | undefined | Your apps default achievement Identifier. Not required. Set this to avoid having to keep passing it in. |

Usage

Basic

const leaderboardIdentifier="high_scores"

  GameCenter.init({leaderboardIdentifier})

Advanced

const leaderboardIdentifier="high_scores"
const achievementIdentifier="novice_award"


//init app
GameCenter.init({leaderboardIdentifier,achievementIdentifier})
  .then(console.log)
  .catch(console.warn)

Player Methods

Player Methods

getPlayer <Promise?>

Details

Gets logged in user.

Parameters

No Parameters

Basic Usage

  GameCenter.getPlayer().then(player=>{
      console.log("player: ", player);
  })

Response

{alias: "Garrettmacmac", displayName: "Me", playerID: "G:8135064222"}

getPlayerImage <Promise?>

Details

Gets logged player image if available. Most players don't have one.

Parameters

No Parameters

Usage

  GameCenter.getPlayerImage().then(image=>{
      console.log("image: ", image);
  })

Success Response

{image: "/path/to/image.png"}

Failed Response

Error fetching player image

getPlayerFriends

Details

Gets a list of players. Most games don't have this anymore as Apple took away the game center App. Now you see lots of users connect via Facebook, SMS and by geolocation.

Parameters

No Parameters

Usage

  GameCenter.getPlayerFriends().then(friends=>{
      console.log("friends: ", friends);
  })

Response

I don't know what this looks like, as I don't have friends 😫 and Apple said they are depreciating support for this is new versions.

Success

[...array of friends]

or

undefined

Failed

Error fetching player friends

Leaderboard Methods

openLeaderboardModal <Promise?>

Details

Opens Game Center Modal on Leaderboard Page

Parameters

No Parameters

Usage

  GameCenter.openLeaderboardModal()
  .then(success=>{})//is open
  .catch(error=>{})//could not open

Success Response

opened leaderboard modal

Failed Response

opened leaderboard modal

submitLeaderboardScore <Promise?>

Details

Submit progress of users leaderboard

Parameters

| Name | Required | Default | Description | |--------------|--------------|--------------|--------------| | score | Yes | n/a | some number to track for leaderboard | | leaderboarIdentifier | No* (see Response) | leaderboarIdentifier set up in Itunes Connect |

Usage

Basic

let options={score:50};

//reverts to default leaderboarIdentifier set up in init()
GameCenter.submitLeaderboardScore(options)
//now update state
this.setState(options)

Advanced

let options={
  score:50,
  leaderboarIdentifier:"some_other_leaderboard"
};

GameCenter.submitLeaderboardScore(options)
  .then(res=>{
    if(res==="Successfully submitted score")
          this.setState({score:50})
  })
  .catch(console.warn("Users progress is not being tracked due to error."))

Response

Success

"Successfully submitted score"

Failed

"Error submitting score."

Achievements Methods

openAchievementModal <Promise?>

Details

Opens Game Center Modal on Leaderboard Page

Parameters

No Parameters

Usage

  GameCenter.openAchievementModal()
  .then(success=>{})//is open
  .catch(error=>{})//could not open

Response

Success

opened achievement modal

Failed

opened achievement modal

getAchievements <Promise?>

Details

Gets players achievements if completed more than 0%. You must declare submitAchievementScore at least once before calling this.

Parameters

No Parameters

Usage

  GameCenter.getAchievements()
  .then(achievements=>{
    console.log(achievements)
    })
  .catch(error=>{})//failed

Response

[{"showsCompletionBanner":false,"lastReportedDate":1506301241432,"completed":true,"percentComplete":100,"identifier":"novice_award"},{"showsCompletionBanner":false,"lastReportedDate":1506301211362,"completed":false,"percentComplete":5,"identifier":"pro_award"}]

or

[]

resetAchievements <Promise?>

[Reset Achievements]

Details

Resets the players achievements.

Parameters

| Name | Required | Default | Description | |--------------|--------------|--------------|--------------| | hideAlert | No | {hideAlert:false} | Hide reset confirmation prompt |

Usage

Basic

  //Triggers confirmation prompt
  GameCenter.resetAchievements()

  // hides confirmation prompt
  GameCenter.resetAchievements({hideAlert:true})

Advanced

  GameCenter.resetAchievements(res=>{
    if(res.resetAchievements){
      do something if user reset achievements
    }
  })
  .catch(alert("Could not reset achievements at this time. Try again later."))

Response

If you pass in {hideAlert:true} into GameCenter.resetAchievements() Method OR the you don't pass in the hideAlert parameter and player presses "Reset"

{"resetAchievements":true,"message":"User achievements reset"}

If you don't pass in the hideAlert parameter and player presses "No!"

{"resetAchievements":false,"message":"User achievements not reset"}

submitAchievementScore <Promise?>

Details

Submit progress of users achievements

Parameters

| Name | Required | Default | Description | |--------------|--------------|--------------|--------------| | percentComplete | Yes | n/a | number, float, or string of the percent achievement is complete. Range 1-100 | | achievementIdentifier | No* (see Response) | achievementIdentifier set up in Itunes Connect | | hideCompletionBanner | No | false | Hides Game center banner when complete |

Usage

let options={
            percentComplete:50,
            achievementIdentifier:"novice_award"
          };

GameCenter.submitAchievementScore(options).then(res=>{
  if(res){
//success
  }
})
.catch(alert("Could not update your achievements at this time. Try again later."))

Response

Success

[null]

Not required if achievementIdentifier set as default in init(). achievementIdentifier always reverts to default unless defended. However, will reject promise if not passed in init() or submitAchievementScore() function

Failed

No Game Center `achievementIdentifier` passed and no default set

TODO

ADD METHODS

[ ] getLeaderboardPlayers() [ ] invite() [ ] challengeComposer() [ ] findScoresOfFriendsToChallenge()