Post not yet marked as solved
this GKAccessPoint code fails on macOS. The AccessPoint button appears, but disappears when clicked -- no modal window. works fine on iOS but not macOS. what am i doing wrong?
import SwiftUI
import GameKit
struct AccessPoint: View {
var body: some View {
ZStack {
Color.clear
Text("GKAccessPoint")
}
.onAppear() {
GKLocalPlayer.local.authenticateHandler = { viewController, error in
GKAccessPoint.shared.isActive = true
}
}
}
}
Post not yet marked as solved
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)
}
Post not yet marked as solved
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?
i have a macOS app that uses Game Center. how do i make it available to beta testers?
i understand that TestFlight is available to developers running macOS v12. but my testers are normal users who are running macOS v11.
my first thought was to sign with a Developer ID and let testers download the app. except that Game Center is not supported in Developer ID apps. Can I sign and upload to App Store Connect and somehow offer the binary to testers?
Post not yet marked as solved
is it possible to write unit tests that involve game center authentication and match methods? this would help a great deal with debugging. or do i need a mock window/view of some kind for authenticateHandler to trigger?class GameCenterTests: XCTestCase {
override func setUp() {
super.setUp()
GKLocalPlayer.local.authenticateHandler = { viewController, error in
...
}
}
func test_EndTurn() {
GKTurnBasedMatch.load(withID:id) { gkTurnBasedMatch, error in
...
}
}
}
Post not yet marked as solved
when I try to authenticate my player (GKLocalPlayer.localPlayer().authenticateHandler) i get the error "status = 5019, no game matching descriptor: macos:org.my.game" the problem is this "org.my.game" bundle identifier is not the same as the bundle identifier specified in my target. in fact it's a previous identifier. i can change the target bundle identifier to any arbitrary string and it doesn't effect the descriptor listed in the error. so is xcode and/or Game Center caching an old identifier for some reason? how can i force Game Center to authenticate me using the bundle identifier in my target? (i've tried all the obvious solutions such as clearing derived data in xcode. i've also confirmed that my desired bundle identifier exists as an App ID in my developer account, as well as having the correct bundle identifier in App Store Connect. Game Center is activated in App Store Connect and in my xcode target's capabilities.)