Create apps that allow players to interact with each other using GameKit.

GameKit Documentation

Posts under GameKit tag

73 Posts
Sort by:
Post not yet marked as solved
0 Replies
273 Views
I'm trying to connect two players with each other using GameKit in a very simple game. I want to use GKMatchmaker.shared().findMatch as I don't want to show any GameCenter related view controllers. (to keep it simple) Problem: Even though GameKit creates a match after finding two players, an error occurs that prevents either player from sending any message to the others. Current Situation: The basic code is as follows (based on the docs described here: https://developer.apple.com/documentation/gamekit/finding_multiple_players_for_a_game) print("Requesting multiplayer match") let request = GKMatchRequest() request.minPlayers = 2 request.maxPlayers = 2 request.recipientResponseHandler = {(player: GKPlayer, respnse: GKInviteRecipientResponse) -> Void in print("new player about to join") print(player.alias) print(respnse) } GKMatchmaker.shared().findMatch(for: request, withCompletionHandler: { (match: GKMatch?, error: Error?) -> Void in if error != nil { // Handle the error that occurred finding a match. print("error during matchmaking") print(error as Any) } else if match != nil { guard let match = match else { return } print("connected to \(match.players.count) players") // load the multiplayer data handler let handler = MultiMatchHandler() match.delegate = handler // load the multiplayer service let service = MultiMatchService(match: match) service.sendMessageToAll(text: "Hello from the other side") // finish the match making GKMatchmaker.shared().finishMatchmaking(for: match) // Start the game with the players in the match. self.view?.presentScene(GameScene.newScene(multiplayer: service)) } }) The output of that is Requesting multiplayer match 2022-01-05 01:19:16.554959+0100 Grapefruit[38300:10026027] [Match] cannot set connecting state for players: ( "<GKPlayer: 0x282add280>(alias:... gamePlayerID:... teamPlayerID:... name:... status:(null) friendBiDirectional:0 friendPlayedWith:1 friendPlayedNearby:0 acceptedGameInviteFromThisFriend:0 initiatedGameInviteToThisFriend:0 automatchedTogether:1)" ), as there is no inviteDelegate set yet. The state might directly change to Ready when we set the inviteDelegate later and call sendQueuedStatesAndPackets. 2022-01-05 01:19:16.557002+0100 Grapefruit[38300:10026027] [Match] syncPlayers failed to loadPlayersForLegacyIdentifiers: ( "..." ) connected to 0 players sending text Hello from the other side failed Findings: minPlayers is set to 2. As the completion handler is called this means that at least one more player was found. But the number of players returned in match.players.count is 0 The matcher shows an error saying that cannot set connecting state for players ... as there is no inviteDelegate set yet. I can't find any info about this invite delegate. Actual Question: What is an inviteDelegate? Do I really need to implement such (if yes, then how?)? (I don't think so as the docs state that the match only starts after the invites are accepted). How can I resolve this issue?
Posted Last updated
.
Post not yet marked as solved
0 Replies
220 Views
wondering if anyone can help clear up an error that i get when calling GKTurnBasedMatch.saveCurrentTurn. this error happens irregularly, but seems to be exacerbated by rapid successive calls to saveCurrentTurn. Error Domain=GKErrorDomain Code=3 "The requested operation could not be completed due to an error communicating with the server." UserInfo={GKServerStatusCode=5002, NSLocalizedDescription=The requested operation could not be completed due to an error communicating with the server., NSUnderlyingError=0x600002e1f480 {Error Domain=GKServerErrorDomain Code=5002 "status = 5002, Unexpected game state version expectedGameStateVersion='d9a7ea8c-f1de-4d35-8607-bc3c9bc1ebda' foundGameStateId='fc0f793d-4b88-4594-9b52-22ce2c1ae4fc' sessionId='1418932146:390cf165-49fc-40fb-aba7-08ff452d8500'" UserInfo={GKServerStatusCode=5002, NSLocalizedFailureReason=status = 5002, Unexpected game state version expectedGameStateVersion='d9a7ea8c-f1de-4d35-8607-bc3c9bc1ebda' foundGameStateId='fc0f793d-4b88-4594-9b52-22ce2c1ae4fc' sessionId='1418932146:390cf165-49fc-40fb-aba7-08ff452d8500'}}} is there a way to avoid this error? here is a unit test that demonstrates the above error -- error happens irregularly but frequently up to 20% of the time. let total:Int = 100 var fail:Int = 0 func test_StressTest_saveCurrentTurn() { guard let match = GKTurnBasedMatch_loadMatches()?.first else { return } for i in 0..<total { GKTurnBasedMatch_saveCurrentTurn(match, Data([UInt8(i)])) } print("failed \(fail) times out of \(total) total") } func GKTurnBasedMatch_saveCurrentTurn(_ match:GKTurnBasedMatch, _ payload:Data) { let expectation = self.expectation(description:"expectation") print("\(Self.self) \(#function)") match.saveCurrentTurn(withMatch:payload) { error in if let error = error { print("\(error)") self.fail += 1 } expectation.fulfill() } wait(for:[expectation], timeout: 5) }
Posted
by Fault.
Last updated
.
Post not yet marked as solved
2 Replies
906 Views
Hi, my achievement completion banner is not showing, but in console it shows the achievement was completed. I have .showCompletionBanner set to true. Is this a sandbox issue? And if it is a sandbox issue does this mean my users won't be affected when it goes live?
Posted
by taptouch.
Last updated
.
Post not yet marked as solved
2 Replies
590 Views
Good afternoon from Germany. I like to update an app to support Game Center but I think I am doing something fundamentally wrong. I created two simple Game Center achievements in App Store Connect for this app and they are marked as not hidden. I can authenticate and log in to Game Center with the app. I can also show the dashboard in Game Center. But then there is nothing to see. Achievements 0 / 0. Should't I see my 2 achievements that I created in App Store Connect? Thank you to bring some light into this darkness :-) Best, Peter
Posted
by toaopeter.
Last updated
.
Post not yet marked as solved
1 Replies
586 Views
I'm adding GameCenter Achievements to my game:           let a = GKAchievement(identifier: "levelcomplete2"); a.percentComplete = 100; GKAchievement.resetAchievements() { (e) in &#9; print("ERRORA: \(e)") } GKAchievement.report([a]) { (e) in &#9; print("ERROR: \(e)");  }; The error shows "nil" but because the Achievement isn't live yet (the App is not published), there's no success-banner showing in the app. How can I test if it's working?
Posted
by Marino123.
Last updated
.
Post not yet marked as solved
9 Replies
824 Views
When Game Center determines a player is forced to disconnect from a match, Game Center sends a disconnect message via the "didChange state" function. However, not all devices connected to the match are receiving the disconnect state change message. One device will think the player is disconnected, but there is still messaging passing from the (supposedly) disconnected player to the other players in the match.The only way I can think to resolve this issue is have all players poll Game Center to obtain updated match information. Based on this updated match information then all players can determine what players are truly still connected properly or not.Can Game Center be polled to obtained updated match information? If so, how?Any other ideas how to resolve the issue when all players do not receive the same disconnect state chaneg from Game Center?
Posted
by uncletr.
Last updated
.
Post not yet marked as solved
0 Replies
208 Views
It seems that some people have asked questions before, but I haven't got an answer, so I'd like to ask you a question. Since playerID is deprecated, when I replaced the relevant part with teamPlayerID, it seems that the format of teamPlayerID obtained from the property of localPlayer and the format of teamPlayerID obtained from Players in GKMatch passed by the delegate function didChangeConnectionState are different. For this reason, comparison by ID is not working well. Is this a malfunction of the OS etc.? Or is there another way to link the teamPlayerID obtained from GKMatch with the teamPlayerID obtained from localPlayer? Also, I haven't figured out the cause yet. I received a report that a program using playerID is not running on monterey. Is playerID completely abolished in monterey?
Posted
by ktab000.
Last updated
.
Post not yet marked as solved
0 Replies
244 Views
I'm certain this has been asked before, but I do not want to use sks files. I have some very old Cocos2d code that I'm trying to port without a complete rewrite. I would rather programatically move my scene sprites around based on the screensize and do it in Obj-C. It is unclear to me how to do this. I sort of found an answer here: https://stackoverflow.com/questions/43927323/are-spritekit-scene-sks-files-necessary-in-my-project Tried to do something equivalent in Obj-C, but got no where.
Posted
by mae1778.
Last updated
.
Post not yet marked as solved
0 Replies
174 Views
GKMatchRequest *request = [[GKMatchRequest alloc] init]; request.recipients = @[ invitePlayer ]; GKMatchmakerViewController *mmvc = [[VCGKMATCHMAKERVIEWCONTROLLER alloc] initWithMatchRequest:request]; [self.parentViewController presentViewController:mmvc animated:YES completion:nil]; Before iOS 15, I can use previous code to present a view and click "Invite and Start" button to invite player to play match, but in iOS 15, the view has 2 buttons "Invite Friends" and "Start Game", both buttons are disabled, and I can't send invite, Does anyone can help me?
Posted
by chctang.
Last updated
.
Post not yet marked as solved
4 Replies
1.1k Views
Hey! My friend and I recently developed an app with leaderboards. We had the scoring system set to higher for testing purposes, leading to me having a score that is relatively unobtainable with the scoring system we launched with. However, when we launched, the leaderboards weren't scrubbed, so my score is way beyond everyone else. My score is the only one affected, so would it be possible to remove my all-time scores and utilize the ones I've earned since our launch? Please let me know!Thank you
Posted
by B-izar.
Last updated
.
Post not yet marked as solved
1 Replies
890 Views
Hi everyone! I'm experiencing an issue about Game Center's authentication behaviour. Login prompt is now displayed immediately if user is not logged in to Game Center on System Settings / Game Center. Expected behaviour (Before 14.5 beta 5): Set callback to authenticateHandler at app launch. Callback fired: If viewController is null, this means user logged in to Game Center and we successfully authenticated user. User sees a Game Center banner says "Signed in as nickname" If viewController is not null, this means user not logged in to Game Center in settings. If you want to show user a login prompt, use viewController. If you don't want to show user a login prompt, end authentication flow and user won't see a login prompt. Current behaviour (After 14.5 beta 5): Set callback to authenticateHandler at app launch. iOS immediately shows login prompt if user not logged in to Game Center, before callback fired. Does anyone encounter same issue? I don't want to show login prompt to users if they are not logged into Game Center. My solution was working fine until 14.5 beta 5. Any help will be appreciated.
Posted Last updated
.
Post not yet marked as solved
7 Replies
3.0k Views
hi, when i create a game with xcode 12 i have black bars on top and bottom on the phone or in the simulator,  scene.scaleMode = .aspectFill doesn't seem to work. if you do the same in Xcode 11 then it works in full screen without problems. is that a mistake or are there new settings for it. if I start the project created with xcode 11 in xcode 12 then it is also in fullscrenn
Posted Last updated
.
Post marked as solved
2 Replies
356 Views
I’m the developer of a health and fitness macOS app called Simon Says previously known as Sluggard. It’s been around for a few years already, and currently I’m working on a new major version update. I am currently considering adding achievements and leaderboards, but I am not sure if a “regular” app is eligible for GameKit and its features. It seems like CloudKit would be more suitable for that. Am I right? GameKit has almost everything I need. The only problem is that my app is not a game at all.
Posted
by msamoylov.
Last updated
.
Post not yet marked as solved
1 Replies
416 Views
Hello every one, I loaded all my friends from Game Center, but every time that I close and start up the game all friends ids change, is this normal? or how can I set the same gamePlayerID and teamPlayerID for all instances? I really appreciate a lot your help IOS version 14.5
Posted
by aarenas.
Last updated
.
Post not yet marked as solved
1 Replies
393 Views
i'm trying to use exchanges and localization. i'm getting different results on iOS versus on macOS. i have the following line in my Localizable.strings (English) file "emote_message_hello" = "hello"; here's my sendExchange function: gkTurnBasedMatch.sendExchange(to:[opponent],                    data:Data(),                    localizableMessageKey:"emote_message_hello",                    arguments:[],                    timeout:TimeInterval(1)) and here is my receivedExchangeRequest function   func player(_ player:GKPlayer, receivedExchangeRequest exchange:GKTurnBasedExchange, for gkTurnBasedMatch: GKTurnBasedMatch) {     print("\(exchange.message)") } on macOS this outputs "hello". yet the same code on iOS outputs "emote_message_hello". in other words it appears that macOS is automatically localizing the string, while iOS is not. am i doing something wrong or is this a bug?
Posted
by Fault.
Last updated
.
Post not yet marked as solved
0 Replies
301 Views
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer]; localPlayer.authenticateHandler = ^(UIViewController * __nullable viewController, NSError * __nullable error) { // not enter this code !!! }; // not open game center auth page.
Posted Last updated
.
Post not yet marked as solved
1 Replies
235 Views
What is the support number for Game Center
Posted Last updated
.