ios: programmatically ask for Game Center sign-in?
I have a simple question, but I’ve looked through Apple’s documentation and done some searching and I can’t find the answer to it.
Is it possible to programmatically pull up Game Center’s sign-in view? I have a
UIButton that requires Game Center, and if the client does not sign in when the app is opened (iOS pulls up the sign-in view at launch), I want to provide a second chance for the user to sign in.
Solutions Collect From Internet About “ios: programmatically ask for Game Center sign-in?”
I’m assuming you’re calling this GKLocalPlayer method on launch:
-setAuthenticateHandler: (>= iOS7) or
-authenticateWithCompletionHandler: (<= iOS6)
If the user cancels the presented login screen, calling these methods again does nothing, or rather, the completion handler is called with an error. The user will then need to login to GameCenter through the GameCenter app or through the Settings app. (While testing, you can login through the GameCenter app, then logout. After that the screen can be presented in your own app again.) You can show an UIAlertView telling the user to login through the GameCenter app.
Alternatively, and I don’t know if this is allowed/approvable, but in iOS7 the
authenticateHandler has a
viewController parameter holding the login screen. If you store this login view controller in an instance variable and the user cancels login, you can present the login screen again later using a
If you try to present the saved login view controller with
-presentViewController:animated:completion: the view controller’s Cancel button no longer works, but using a
UINavigationController hides the Cancel button and allows navigation back to your own view controller.
You’ll also need to hide the login screen manually after the user logs in by responding to
GKPlayerAuthenticationDidChangeNotificationName. It doesn’t seem like developers were intended to be able to do this, so it may not pass approval, but it works!
- XCode fails to run app on device, saying the program being debugged is not being run
- Issue when using MFMailComposeViewController
- Description of NSDictionary – why are some key names with quotes?
- Getting the parameterised type of a generic in swift?
- Stop an auto-reverse / infinite-repeat UIView animation with a BOOL / completion block
- Pattern match and conditionally bind in a single Switch statement
- Trying to convert Firebase timestamp to NSDate in Swift
- how to have 2 different setting page with inappSettings
- Draw a Line Sprite Between Two Points made by Sprites in Cocos2d
- Implementing a function with a default parameter defined in a protocol
- AVcapture session slow launch after session restart
- Implementing a method taking a block to use as callback
- Using existing system sounds in iOS App [swift|
- hitTest fires when UIKeyboard is tapped
- iOS: NSString loses URL, (null) is shown