Apple GameKit Game Center Extension

The GameKit native extension and demo Defold project I’ve been working on is now released:

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. It will be replaced with gamePlayerID and teamPlayerID:

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.

12 Likes

Really cool. Please submit it to the asset portal!

5 Likes

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.

3 Likes

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

2 Likes

Game Center Real-Time Match features have been added to the extension and pushed to GitHub.

I’ll continue to work on the Game Center Save Game Data features as soon as this Defold bug with iOS entitlements not merging is fixed.

5 Likes

WOW this is great! Thanks a lot

1 Like

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.

Edit 2: Found it in the example project, here. It’s on_gc_signin( self, event ).

1 Like

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.

1 Like

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.

2 Likes

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.

2 Likes

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

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.

2 Likes

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.

2 Likes

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?

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.

2 Likes

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

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

I ended up using this one by @Dragosha for my recent iOS release. Works great if all you need are leaderboards & achievements: 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!): 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.

2 Likes

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

What was the error you were getting?