I have found multiple versions of the same code to authenticate a user in GameCenter, and every version seems to not want to work (when opening the app in the simulator, absolutely nothing pops up, there are no prompts from GameCenter, etc). This is mostly based off of what Apple has online, but this is my code (note that the viewfinder I am using is called AchievementsViewFinder, and I am just trying to ensure it either appears on that page or when the user first opens the app, either works):
import Foundation
import GameKit
import UIKit
class AchievementsViewController: UIViewController{
override func viewDidLoad() {
super.viewDidLoad()
authenticateUser()
}
private func authenticateUser(){
let player = GKLocalPlayer.local
player.authenticateHandler = { AchievementsViewController, error in
guard error == nil else{
print(error?.localizedDescription ?? ""); return
}
self.presentViewController(vc!, animated: true, completion: nil)
}
}
@IBAction func showAchievements(_ sender: Any) {
}
@IBAction func showLeaderboards(_ sender: Any) {
}
@IBAction func unlockAchievements(_ sender: Any) {
}
@IBAction func submit(_ sender: Any) {
}
}
I think me adjusting the viewfinder is what is causing my code to not work, but after trying different solutions (mostly on stackoverflow) I realized that a lot of people have pretty different ways of tackling the same code. Any help would be appreciated, even if it's completely rewriting what I have.
"I've tried summarizing it."
Issues
1. Authentication Handler Implementation
Solutions
1. Check GameCenter Settings
2. Verify Authentication UI Code
3. Simulator Check
4. Review Authentication Handler Code
Reference