CloudKit and GameCenter in a game? - ios

I am working on a game. It will use Game Center for multiplayer. I would like to be able to use CloudKit for storing levels and the local CloudKit container for storing game progress. The problem is that this requires to different accounts. Any ideas on how to link them together?

I struggled with this recently when building in syncing to my game Qiktionary. At first I associated single player game data with the currently logged in Game Center player. So when I started working on sync, I was associating the single player game data in CloudKit with the Game Center player by using a separate CKRecordZone (in the private db) for each Game Center player.
I ended up abandoning that approach because it turns out that causes some behaviour that looks to the user like data loss. For example, GC Player A is logged into your game and plays 10 single player games (or in your case, levels). Later they happen to log out of Game Center, and even later than that they come back to your game and since they are logged out, they no longer see their 10 games played. It's not obvious that the game data is there but just "missing" because they are now logged out of GC.
I did some research and most other games don't work like that. Single player game progress is not linked to the logged in Game Center player. Which means that the single player game data in CloudKit shouldn't be linked to the Game Center player either.
This is even how the GKSavedGame API from GameKit works. According to the docs:
Saved games are tied to the iCloud account, not the Game Center account

Related

can you create multiplayer game on ios without enabling game center

I am trying to understand to what extent the games that have game center enabled are multiplayer games. Please help me understand following questions:
a) Is it possible to create a multi-player game without enabling game-center
b) Can a game with game-center enabled be a single-player game.
Is it possible to create a multi-player game without enabling game-center?
It is definitely possible, but harder to spin up. Without GameCenter, you need to create your own servers, store game sessions, handle game data being transferred from player to player, and other non-trivial things. GameCenter basically says “Don’t worry about all that network and infrastructure, we got it covered. All you need to do is use our framework.”
Can a game with game-center enabled be a single-player game?
Also a yes! You can actually build a game without GameCenter and let you app handle everything. GameCenter is useful here when you want to add a leaderboard, let players compete with other players, enable high scores, etc.

Can Game Center Track total time played?

Curious to know if Game Center tracks total time played per app? If it does, how could I easily query this data?
Thanks!
No, you cannot use game center to do this. There are a couple of options though.
You can track it locally, and then upload the data to a game center leaderboard. I don't know if you want to do that though because then everyone can see how much a certain player has played
You can use some sort of analytics service, like Google Analytics and ping it periodically while a player is on the app so you can see how much people are playing
Or you can set up a server and database, where the player sends their play time when they are on the app

What is a "guest player" in GameKit?

The documentation for GKPlayer mentions a method for creating "guest players":
The concept of guest players is introduced in iOS 9. Guest players are
treated exactly like authenticated players for Game Center multiplayer
purposes. However, guest players cannot earn achievements, post to
leaderboards, or participate in challenges. Create a guest player with
the anonymous​Guest​Player(with​Identifier:​) method.
But the same documentation says there must be an authenticated player before using GameKit. And indeed, pretty much everything GameKit fails if you aren't logged into Game Center.
So what is the purpose of "guest players" and how would you use them?
its like : lets say your friend wants to play a game(that you also play) using your device. In that case your friend can directly play the game without effecting your scores and achievements if he plays as a guest. Its like a temporary way to play a game from someone else GameCenter account but without affecting his/her scores and achievements

iOS Google Play Games SDK - How to invite friends to social circles?

Apple's Game Center has really gone down the toilet recently so I'm adding support for Google Play Games leaderboards and achievements to my iOS games. I'm displaying the leaderboards myself by downloading the scores using the GPGLeaderboard class. There's a property called "social" that lets me download the scores of friends - "A social leaderboard is a public leaderboard filtered by people within the local player's circles." Is there an API that will let me invite other players to my game so I can see them in these social leaderboards? I'm not sure how people are supposed to set up these social circles?
Check this documentation: Starting a real-time multiplayer game.
Invite players button. Lets the user invite friends to join a game session or specify some number of random opponents for auto-matching. When the player selects this option, your app should display either the built-in player selection user interface (UI) provided by the SDK or a custom UI for player selection.
You might also want to check on this GPGLeaderboard Class Reference wherein leaderboard objects must be created with a leaderboard ID. Once a leaderboard object is created, you may interact with it using the provided set of actions.

Game Kit Send data to offline player

I am pretty sure i know the answer but is it possible to send data using game kit to a player who is not playing the game anymore so next time he loads the game the data will be there. Is there any sort of messaging queue in gamecenter that can hold data
Nope, this is not possible if you let Game Center host the game. But you can set up your own server which stores the data and hands it over to the client while still having Game Centers match making functionality.

Resources