ios - Present GameCenter authenticationVC again -
i'm facing little issue here , hope me figure out wrong.
*the test project presented below can find here : http://goo.gl/wz84aa (fr) or https://goo.gl/0m8lrz (mega.nz) *
i'm trying present user authentification view controller proposed apple gamecenter feature. more precisely, re-present if canceled on first time.
i have game storyboard :
gamenavigationcontroller :
class gamenavigationcontroller: uinavigationcontroller { override func viewdidload() { super.viewdidload() nsnotificationcenter.defaultcenter().addobserver(self, selector: selector("showauthenticationviewcontroller"), name: presentauthenticationviewcontroller, object: nil) gamekithelper.sharedinstance.authenticatelocalplayer() } func showauthenticationviewcontroller() { let gamekithelper = gamekithelper.sharedinstance if let authenticationviewcontroller = gamekithelper.authenticationviewcontroller { self.topviewcontroller.presentviewcontroller(authenticationviewcontroller, animated: true, completion: nil) } } deinit { nsnotificationcenter.defaultcenter().removeobserver(self) } }
menuviewcontroller :
class menuviewcontroller: uiviewcontroller { @ibaction func didtapleaderboardbtn() { // try 2 //if ( !gamekithelper.sharedinstance.gamecenterenabled) { gamekithelper.sharedinstance.authenticatelocalplayer() //} else { gamekithelper.sharedinstance.showgkgamecenterviewcontroller(self) //} } }
gamekithelper :
import gamekit import foundation let presentauthenticationviewcontroller = "presentauthenticationviewcontroller" let singleton = gamekithelper() class gamekithelper: nsobject, gkgamecentercontrollerdelegate { var authenticationviewcontroller: uiviewcontroller? var lasterror: nserror? var gamecenterenabled: bool class var sharedinstance: gamekithelper { return singleton } override init() { gamecenterenabled = true super.init() } func authenticatelocalplayer () { let localplayer = gklocalplayer.localplayer() localplayer.authenticatehandler = { (viewcontroller, error) in self.lasterror = error if viewcontroller != nil { self.authenticationviewcontroller = viewcontroller nsnotificationcenter.defaultcenter().postnotificationname(presentauthenticationviewcontroller, object: self) } else if localplayer.authenticated { self.gamecenterenabled = true } else { self.gamecenterenabled = false } } } func showgkgamecenterviewcontroller(viewcontroller: uiviewcontroller!) { if ( !self.gamecenterenabled ) { println("local player not authenticated") // try 1 //self.authenticatelocalplayer() return } let gamecenterviewcontroller = gkgamecenterviewcontroller() gamecenterviewcontroller.gamecenterdelegate = self gamecenterviewcontroller.viewstate = .leaderboards viewcontroller.presentviewcontroller(gamecenterviewcontroller, animated: true, completion: nil) } func gamecenterviewcontrollerdidfinish(gamecenterviewcontroller: gkgamecenterviewcontroller!) { gamecenterviewcontroller.dismissviewcontrolleranimated(true, completion: nil) } }
what working :
- if user logged-in (within gamecenter app) he's able open leaderboard view ;
- if user wasn't logged-in he's prompted log-in when game navigation controller loaded (and open leaderboard).
what not working :
- if cancel 3 time authentification, authentification won't appear anymore (even @ launch) ; // apparently known "problem", not "fixable"
- if user cancel authentification, when tries load leaderboard authentification won't appear again.
i tried 2-3 things can see in commented code above, none of them working ; can't make authentification view appear again.
ps : code written in swift, in objective-c welcomed well.
as have found out, if game center authentication dialog canceled 3 times, can't bring without resetting device.
there "security feature" built game center not allow app re-authenticate if user has canceled dialog without leaving app. authentication dialog show, user must leave , re-enter app.
there no way around it. i've done in couple of projects display message user:
game center not available. please make sure signed in through game center app
i show message after trying authenticate , if game center isn't available or user not signed in.
Comments
Post a Comment