ios:以编程方式请求Game Center登录? [英] ios: programmatically ask for Game Center sign-in?

查看:167
本文介绍了ios:以编程方式请求Game Center登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的问题,但我查看了Apple的文档并进行了一些搜索,我找不到答案。

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.

是否有可能以编程方式拉出Game Center的登录视图?我有一个需要Game Center的 UIButton ,如果客户端在应用程序打开时没有登录(iOS在启动时拉出登录视图),我想要为用户提供第二次登录的机会。

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.

推荐答案

我假设您在启动时调用此GKLocalPlayer方法: -setAuthenticateHandler:(> = iOS7)或 -authenticateWithCompletionHandler:(< = iOS6)

I'm assuming you're calling this GKLocalPlayer method on launch: -setAuthenticateHandler: (>= iOS7) or -authenticateWithCompletionHandler: (<= iOS6)

如果用户取消显示的登录屏幕,则再次调用这些方法不会执行任何操作,或者更确切地说,调用完成处理程序时会显示错误。然后,用户需要通过GameCenter应用程序或设置应用程序登录GameCenter。 (测试时,您可以通过GameCenter应用程序登录,然后注销。之后,屏幕可以再次显示在您自己的应用程序中。)您可以显示UIAlertView,告诉用户通过GameCenter应用程序登录。

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.

或者,我不知道这是否允许/可批准,但在iOS7中, authenticateHandler 有一个 viewController 保存登录界面的参数。如果将此登录视图控制器存储在实例变量中并且用户取消登录,则可以稍后使用 UINavigationController 再次显示登录屏幕。

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 UINavigationController.

如果您尝试使用 -presentViewController呈现已保存的登录视图控制器:动画:完成:视图控制器的取消按钮不再有效,但使用 UINavigationController 隐藏了取消按钮,并允许导航回您自己的视图控制器。

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.

您还需要在用户登录后通过响应 GKPlayerAuthenticationDidChangeNotificationName 手动隐藏登录屏幕。似乎开发人员不打算这样做,所以它可能无法通过批准,但它确实有效!

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!

这篇关于ios:以编程方式请求Game Center登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆