# Apple GameKit Game Center Extension

**URL:** <https://forum.defold.com/t/apple-gamekit-game-center-extension/64372>\
**Category:** The Defoldmine\
**Created:** [February 1, 2020, 6:54pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372 "2020-02-01T18:54:18Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![animonger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/animonger/32/19118_2.png) [@animonger](https://forum.defold.com/u/animonger)\
**Post date:** [February 1, 2020, 6:54pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/1 "2020-02-01T18:54:18Z")

</div>

The GameKit native extension and demo Defold project I’ve been working on is now released:  
[https://github.com/animonger/extension-gamekit](https://github.com/animonger/extension-gamekit)

It is still a work in progress but the following integrated GameKit features are functional:  
Players, Leaderboards, Achievements, View Controllers and Errors.

I’ll be adding Real-Time Matches next.

Possible GameKit features to be integrated: Challenges, Player Invitations, Notifications, Entitlements, Turn-based Games and Save Game Data.

Thanks to @RG1, @Dragosha, @britzl and @sergey.lerg for their public code examples, it really helped me understand how native extensions are done in Defold.

Note, this extension uses Game Center playerID to support lower iOS versions than iOS 13.  
As of iOS 13, Game Center [playerID is deprecated](https://developer.apple.com/documentation/gamekit/gkplayer/1521127-playerid?language=objc). It will be replaced with [gamePlayerID](https://developer.apple.com/documentation/gamekit/gkplayer/3113960-gameplayerid?language=objc) and [teamPlayerID](https://developer.apple.com/documentation/gamekit/gkplayer/3174857-teamplayerid?language=objc):

> **[Game Center Player Identifiers - WWDC19 - Videos - Apple Developer](https://developer.apple.com/videos/play/wwdc2019/615/)**
>
> Game Center now supports persistent player identifiers scoped to individual games or to a developer team ID. Understand how scoped...

I don’t own an iOS 13 device, so I haven’t been able to test what happens to playerID in iOS 13.  
If you find any bugs or have any questions please post them here.

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 1, 2020, 7:23pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/2 "2020-02-01T19:23:26Z")

</div>

Really cool. Please submit it to the asset portal!

---

<div class="post-metadata">

**Author:** ![radiofreelunch](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/radiofreelunch/32/19336_2.png) [@radiofreelunch](https://forum.defold.com/u/radiofreelunch)\
**Post date:** [February 23, 2020, 10:25pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/3 "2020-02-23T22:25:58Z")

</div>

I haven’t switched to Defold but my native game uses playerID and I just checked in the iOS 13 Simulator. It is still the same string it’s always been.

---

<div class="post-metadata">

**Author:** ![animonger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/animonger/32/19118_2.png) [@animonger](https://forum.defold.com/u/animonger)\
**Post date:** [February 23, 2020, 10:42pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/4 "2020-02-23T22:42:22Z")

</div>

Good to know playerID still works in iOS 13 as well. @radiofreelunch, Thanks for the info.

---

<div class="post-metadata">

**Author:** ![animonger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/animonger/32/19118_2.png) [@animonger](https://forum.defold.com/u/animonger)\
**Post date:** [May 1, 2020, 8:39pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/5 "2020-05-01T20:39:09Z")

</div>

Game Center [Real-Time Match](https://github.com/animonger/extension-gamekit/blob/master/README.md#real-time-matches) features have been added to the extension and pushed to GitHub.

I’ll continue to work on the Game Center [Save Game Data](https://developer.apple.com/documentation/gamekit/gksavedgame?language=objc) features as soon as this [Defold bug](https://github.com/defold/editor2-issues/issues/2925) with iOS entitlements not merging is fixed.

---

<div class="post-metadata">

**Author:** ![gianmichele](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gianmichele/32/24028_2.png) [@gianmichele](https://forum.defold.com/u/gianmichele)\
**Post date:** [May 2, 2020, 10:14am UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/6 "2020-05-02T10:14:56Z")

</div>

WOW this is great! Thanks a lot

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [July 23, 2020, 11:20am UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/7 "2020-07-23T11:20:58Z")

</div>

I’m integrating this extension now and can’t seem to get a response from  
`gamekit.gc_signin()`.

I’ve created a debug build which I’ve uploaded to Testflight. I’m using a sandbox account.

This is the code:

```
local gamekit_is_logged_in

if gamekit then

	local function on_gc_signin( event ) -- This function is never triggered

		pprint( "	on_gc_signin()", event )
		
		if event.type == "showSignInUI" then -- Player hasn't previously logged in
			gamekit.gc_show_signin("UI") -- Show UI to log in
		else
			gamekit_is_logged_in = event.type == "authenticated" -- Player was silently logged in
		end
		
	end

	print( "gamekit.gc_signin()", on_gc_signin )
	
	gamekit.gc_signin(on_gc_signin)

end

```

Any idea where I’m going wrong? The Console doesn’t seem to show a clear error message.

Edit 1: There IS a callback, but the first variable seems to be self, rather than “event”. So the question becomes, which variables are returned by the gc\_signin() callback? It doesn’t seem documented [here](https://github.com/animonger/extension-gamekit/blob/master/README.md#initialize-local-player).

Edit 2: Found it in the example project, [here](https://github.com/animonger/extension-gamekit/blob/master/main/game_center.script#L264). It’s `on_gc_signin( self, event )`.

---

<div class="post-metadata">

**Author:** ![animonger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/animonger/32/19118_2.png) [@animonger](https://forum.defold.com/u/animonger)\
**Post date:** [July 23, 2020, 3:31pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/8 "2020-07-23T15:31:27Z")

</div>

I’m currently off grid and away from my computer but I will be able to look into your question this Saturday the 25th when I return. In the meantime the example project on GitHub might have a solution for you.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [July 23, 2020, 4:07pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/9 "2020-07-23T16:07:55Z")

</div>

> [@animonger](#):
>
> In the meantime the example project on GitHub might have a solution for you.

Yes, it all works now, thanks! In the end the problem was that I didn’t know what the gc\_signin() returned, because it was missing in the documentation. A quick check in the example made it clear.

---

<div class="post-metadata">

**Author:** ![animonger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/animonger/32/19118_2.png) [@animonger](https://forum.defold.com/u/animonger)\
**Post date:** [July 25, 2020, 3:43pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/10 "2020-07-25T15:43:15Z")

</div>

> [@totebo](#):
>
> Edit 1: There IS a callback, but the first variable seems to be self, rather than “event”. So the question becomes, which variables are returned by the gc\_signin() callback? It doesn’t seem documented

Good point, I’ll add a description for the self parameter in the callback functions to the documentation.  
Glad to hear you were able to solve your problem from looking at the example code.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [July 27, 2020, 3:36pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/11 "2020-07-27T15:36:51Z")

</div>

I trigger the sign in as the app starts. If the player cancels this, is there a way to trigger it again?

Calling `gamekit.gc_signin()` from a button in game returns this message:

```
ERROR:GAMEKIT: Game Center is enabled, call gc_signin() only one time after your game launches

```

I also tried to call `gamekit.gc_show_signin("UI")` resulting in this message:

```
ERROR:GAMEKIT: You must receive the 'showSignInUI' event before you call gc_show_signin('UI')

```

---

<div class="post-metadata">

**Author:** ![animonger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/animonger/32/19118_2.png) [@animonger](https://forum.defold.com/u/animonger)\
**Post date:** [July 27, 2020, 9:49pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/12 "2020-07-27T21:49:22Z")

</div>

Apple won’t allow you to force or nag the local player to sign into game center. If the local player cancels the sign in UI for that session, you could pop up information explaining the benefits the user would get in your game and how to sign into game center through the device’s game center settings.

If the local player cancels the sign in UI 3 consecutive times on 3 consecutive game launches, game center will stop showing the sign in UI at game launch until the local player signs into game center through the device’s game center settings.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [July 27, 2020, 10:33pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/13 "2020-07-27T22:33:26Z")

</div>

Thanks @animonger, that makes sense. So, basically, Apple doesn’t allow more than one sign in prompt per session and, cursed be the mere thought, not more than three in total.

Reading your answer reminded me I have battled with this before. It used to be irreversible, and the player had to wipe the phone to allow logins for a game. At least now you can solve it by using settings to sign in.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 7, 2021, 4:23pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/14 "2021-06-07T16:23:04Z")

</div>

> [@animonger](#):
>
> I’ll continue to work on the Game Center [Save Game Data](https://developer.apple.com/documentation/gamekit/gksavedgame?language=objc) features as soon as this [Defold bug](https://github.com/defold/editor2-issues/issues/2925) with iOS entitlements not merging is fixed.

Hi @animonger, have you been able to look at cloud saves yet? I believe the Defold bug that was in the way has now been squashed?

---

<div class="post-metadata">

**Author:** ![animonger](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/animonger/32/19118_2.png) [@animonger](https://forum.defold.com/u/animonger)\
**Post date:** [June 8, 2021, 5:17pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/15 "2021-06-08T17:17:52Z")

</div>

Hi @totebo , unfortunately all my development projects are on hold during this current state of endless lockdowns, supply chain issues and vax shunning. I am in the process of moving to another state that has more freedoms than California. This transition is my main focus for at least the next 6 months.

---

<div class="post-metadata">

**Author:** ![totebo](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/totebo/32/36087_2.png) [@totebo](https://forum.defold.com/u/totebo)\
**Post date:** [June 8, 2021, 5:39pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/16 "2021-06-08T17:39:55Z")

</div>

No worries @animonger, thanks for the heads up. I hope things improve for you (and the world…).

---

<div class="post-metadata">

**Author:** ![gianmichele](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gianmichele/32/24028_2.png) [@gianmichele](https://forum.defold.com/u/gianmichele)\
**Post date:** [February 10, 2023, 3:30pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/17 "2023-02-10T15:30:08Z")

</div>

Hi there,  
is this extension still valid? I can see it has not been updated in quite a while.

---

<div class="post-metadata">

**Author:** ![SkaterDad](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/skaterdad/32/41137_2.png) [@SkaterDad](https://forum.defold.com/u/SkaterDad)\
**Post date:** [February 10, 2023, 3:55pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/18 "2023-02-10T15:55:40Z")

</div>

I ended up using this one by @Dragosha for my recent iOS release. Works great if all you need are leaderboards & achievements: [GitHub - Dragosha/extension-gamecenter · GitHub](https://github.com/Dragosha/extension-gamecenter)

I needed to be able to query the player’s high scores, and added that in a fork (my first exposure to Objective C… what a strange language!): [GitHub - SkaterDad/extension-gamecenter · GitHub](https://github.com/SkaterDad/extension-gamecenter)

The extension in this thread has quite a bit more ambition to cover more GK features. Would be really interesting if the multiplayer & cloud save stuff works.

---

<div class="post-metadata">

**Author:** ![gianmichele](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/gianmichele/32/24028_2.png) [@gianmichele](https://forum.defold.com/u/gianmichele)\
**Post date:** [February 10, 2023, 4:23pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/19 "2023-02-10T16:23:02Z")

</div>

Thanks. That’s the one I used in a previous game, and it worked great.  
Was testing the waters since this feels more feature complete, but it’s also not building in 1.4.2

---

<div class="post-metadata">

**Author:** ![britzl](https://forum-defold.b-cdn.net/user_avatar/forum.defold.com/britzl/32/23_2.png) [@britzl](https://forum.defold.com/u/britzl)\
**Post date:** [February 10, 2023, 7:12pm UTC](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372/20 "2023-02-10T19:12:50Z")

</div>

> [@gianmichele](#):
>
> Was testing the waters since this feels more feature complete, but it’s also not building in 1.4.2

What was the error you were getting?

[Next page](https://forum.defold.com/t/apple-gamekit-game-center-extension/64372.md?page=2)
