游戏中心登录提醒

发布于 2024-10-05 09:46:52 字数 660 浏览 0 评论 0原文

在我使用 GameCenter 开发的游戏中,我想处理以下场景:

  1. 用户启动游戏。他会看到系统警报,提示他登录 GameCenter。他暂时忽略它。
  2. 一段时间后,用户想要登录 GameCenter 并单击(例如)排行榜菜单项。他暂时选择了取消而不是登录。
  3. 该过程重复多次。最终用户确实想要登录 GameCenter。他再次单击“排行榜”菜单项。

在我的测试中,我发现调用“authenticateWithCompletionHandler”(由 Apple 的示例 GameCenterManager 调用)引发的警报弹出窗口仅出现有限次数(4 或 5 次),建议登录 GameCenter。最后一次出现时,它显示“游戏中心已禁用,请使用游戏中心应用程序登录以启用”之后”。之后,调用authenticateWithCompletionHandler不再执行任何可见操作 - 根本没有提示。

玩FruitNinja时我尝试复制这一点。但是,在他们的情况下,每次我单击游戏中心项目(例如成就)时,都会出现“游戏中心已禁用”的弹出窗口,

我想做的是复制该功能:也就是说,如果您没有这样做。登录到 GameCenter 后,每次单击排行榜菜单项时都会显示标准游戏中心警报。

有没有办法了解标准“登录游戏中心”警报是否已出现,或强制其出现。任何时候(而不仅仅是前几次尝试)?

In a game I am developing using GameCenter, I want to handle the following scenario:

  1. the user starts up the game. He is shown the system alert that prompts him to log on GameCenter. He ignores it for now.
  2. after a while, the user wants to log in to GameCenter and clicks on(for instance) the Leaderboards menu item. He choses cancel instead of Log in, for now.
  3. the process repeats several times. Eventually the user DOES want to log in to GameCenter. He clicks the Leaderboard menu item one more time.

In my tests, I have found that the alert popup raised by the call to "authenticateWithCompletionHandler" (as invoked by Apple's sample GameCenterManager) which suggests to log in to GameCenter only appears a limited number of times(4 or 5). The last time it appears, it says "Game Center Disabled, sign in with the Game Center application to enable"Afterwards". Afterwards, calling authenticateWithCompletionHandler no longer does anything visible -no prompt at all.

Playing FruitNinja I tried to replicate this. However, in their case, the popup saying "Game Center Disabled" does appear every time I click on a GameCenter item(Achievements, for instance).

What I'd like to do is to duplicate the functionality: that is, if you are not logged in to GameCenter, to have the standard game center alert appear all the times you click on the Leaderboard menu item.

Is there a way to learn whether the standard 'log in to game center' alert has appeared, or to force it to appear at all times(and not just the first couple of tries)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

穿透光 2024-10-12 09:46:52

这里有一个解决此问题的想法:

无论“GCauthenticateWithCompletionHandler”请求是

  • 由用户在对话框中点击“取消”

取消的,还是由于

  • 设备上禁用了 GC(这发生在用户已经取消警报对话框 3 次(至少在 iOS 5 中)),

您将始终收到一个 NSError,代码为 2,表示“请求的操作已被取消。”。

我能找到的唯一区别是authenticateWithCompletionHandler-Request 和completion-Handler 的执行之间传递的时间。

因此,在发送请求时,我节省了时间:

requestTime = [NSDate date]; 

并且在完成处理程序中,我测量了经过的时间:

NSDate* now = [NSDate date];
CFTimeInterval elapsedTimeSinceAuthenticationRequest = [now timeIntervalSinceDate:requestTime];
NSLog(@"time Elapsed: %f", elapsedTimeSinceAuthenticationRequest);

如果用户取消了请求,则所经过的时间将比 GC 取消操作所经过的时间明显更长。在我的测试中,用户至少需要一秒钟才能取消对话框,而 GC 取消的请求则需要不到 0.1 秒(在我的 iPhone 4 上)。

当然,这些值可能会有所不同,具体取决于代码运行的设备和处理器目前还忙着什么。我已经检查过的一个陷阱是应用程序启动:如果您按照 Apple 的建议在 applicationDidFinishLaunching 期间发送authenticationRequest,则在我的情况下,GC 需要更长的时间才能取消请求,因为设备正忙于加载视图以及启动所需的任何内容该应用程序。

因此,请告诉我您是否尝试过此解决方案以及它是否对您有效,一旦我完成了进一步的测试,我也会...

Here's an is an idea to workaround this issue:

No matter if a "GC authenticateWithCompletionHandler"-Request is cancelled

  • by the user tapping "Cancel" in the dialog

or due to the fact that

  • GC is disabled on the device (which happens after the user has cancelled the alert-dialog exactly 3 times (in iOS 5 at least))

you will always receive an NSError with code 2 saying "The requested operation has been cancelled.".

The only differentiator that i could find is the time passed between the authenticateWithCompletionHandler-Request and the the execution of the completion-Handler.

So when sending the request i am saving the time:

requestTime = [NSDate date]; 

and in my completion handler i measure the time lapsed:

NSDate* now = [NSDate date];
CFTimeInterval elapsedTimeSinceAuthenticationRequest = [now timeIntervalSinceDate:requestTime];
NSLog(@"time Elapsed: %f", elapsedTimeSinceAuthenticationRequest);

If the user cancelled the request, the time passed will be significantly longer compared to the time passed if GC cancelled the operation. In my tests, it took a user at least one second to cancel the dialog, whereas a GC-cancelled request took less than 0.1 seconds (on my iPhone 4)

Of course, these values may vary depending on the device the code runs on and on what else the processor is busy with at the moment. One pitfall i already examined is the application launch: If you are sending the authenticationRequest during applicationDidFinishLaunching as suggested by Apple, it took much longer for GC to cancel the request in my case, because the device is busy loading views and whatever is necessary to launch the app.

So let me know if you tried this solution and if it worked for you, as will i once i have done further testing...

空城旧梦 2024-10-12 09:46:52

该行为的结果是,在 N 次不成功的尝试之后 - 禁用应用程序的 GameCenter。重新启动应用程序或登录游戏中心即可使其恢复在线状态。

我忘记了我在哪个文档中读到过这个,但是有一个 Apple 文档解释了这种行为。

The behavior is something to the effect of, after N unsuccessful attempts - disable GameCenter for the app. Restarting the app or going to login in gamecenter itself will get it back online.

I forget which doc I read this in, but there is an Apple doc out there that explains this behavior.

半寸时光 2024-10-12 09:46:52

我也找不到一个好的答案,所以我决定在开始收到取消错误时复制该消息。这仍在开发中,但它基本上改变了按钮回调以显示错误警报而不是显示排行榜。

请注意,不确定这是否会被批准,因为我正在复制 Apple 错误消息。

-(void) gcLogin: (id) sender {
    [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
        if(error) {
            if([[error domain] isEqualToString:GKErrorDomain] && [error code] == GKErrorCancelled) {
                [ResourceManager showAlertWithTitle:@"GameCenter Disabled" message:@"Sign in with Game Center application to enable"];
                mGameCenterCancelled = YES;
            }
            NSLog(@"%@", [error description]);
        } else { 
            [self updateMenu];
            mGameCenterCancelled = NO;
        }
    }];
}

I couldn't find a good answer for this either, so I decided to just replicate the message once the I start getting the cancel error. This is still in development but it basically changes the button callback to display the error alert rather than display the leader-board.

Just a note, not sure if this will be approved or not since I am replicating an Apple error message.

-(void) gcLogin: (id) sender {
    [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error) {
        if(error) {
            if([[error domain] isEqualToString:GKErrorDomain] && [error code] == GKErrorCancelled) {
                [ResourceManager showAlertWithTitle:@"GameCenter Disabled" message:@"Sign in with Game Center application to enable"];
                mGameCenterCancelled = YES;
            }
            NSLog(@"%@", [error description]);
        } else { 
            [self updateMenu];
            mGameCenterCancelled = NO;
        }
    }];
}
下雨或天晴 2024-10-12 09:46:52

我现在正在玩游戏中心,我也看到了同样的行为。文档中没有任何内容说明该对话框仅在前几次出现。
就我而言,我希望有一种方法可以提前告知用户是否已经登录游戏中心,以便我可以采取适当的行为。但现在在向用户显示对话框之前我无法知道这一点。

由于我们在开发过程中在沙箱中运行,这种行为当然可能与生产过程中的行为有所不同,但这并不是一件容易发现的事情。

I am playing around with Game Center myself right now I have seen the very same behavior. There is nothing in the documentation saying anything about the dialog only showing up the first couple of times.
In my case I would like a way to tell beforehand if the user is already logged into Game Center, so that I can behave appropriately. But now I can not know this before the dialog is shown to the user.

Since we are running in the sandbox during development this behavior might of course be something that behaves differently during production but this is not an easy thing to find out.

可遇━不可求 2024-10-12 09:46:52

我面临着同样的问题。虽然我找不到一种方法来强制弹出相同的对话框来登录游戏中心,但我确实找到了一种方法来实现当用户单击排行榜图标时显示“游戏中心已禁用”的警告消息:

if([GKLocalPlayer localPlayer].authenticated == NO)
{
// 提示游戏中心已禁用的警告消息
}
否则
{
// 继续打开排行榜
}

这有帮助!

I'm facing the same issue. Though I couldn't find a way to enforce poping up the same dialog for logging into Game Center, I did find a way to implement a warning message saying 'gamecenter is disabled' when user clicks on a leaderboard icon:

if([GKLocalPlayer localPlayer].authenticated == NO)
{
// Prompt a warning message alert saying game center is disabled
}
else
{
// Proceed with opening leaderboard
}

Hope this helps!

我爱人 2024-10-12 09:46:52

看来,iOS 将完全禁用 Game Center,并在用户选择禁用 Game Center 后阻止其提示(该选项将出现在您第五次取消登录 Game Center 时)。

将设备恢复到原始状态,此时将再次出现登录提示。只需使用正常工作的 Game Center 帐户(非测试人员)登录 Game Center 应用程序即可。进入后,退出。它应该开始在您的应用程序中再次提示您。

It appear that iOS will disable Game Center completely and prevent it from prompting after the user chooses to Disable Game Center (the option would appear on your fifth 5th Game Center cancel sign in).

To restore the device to the original state where the login prompt will appear again. Simply sign in using the Game Center app using a normal working Game Center account (non Tester). Once you are in, Sign Out. It should start prompting you again on within your app.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文