游戏中心URL方案

21

可以使用以下方法从您自己的应用程序打开Game Center应用:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:"]];
有没有一种方法可以在页面上为特定的游戏打开它?

除了在这里概述的常规GameKit交互之外,您想要做什么?http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/LeaderBoards/LeaderBoards.html#//apple_ref/doc/uid/TP40008304-CH6-SW13 - brindy
虽然可以在应用内显示排行榜和成就,但我希望能够通过按钮打开实际的Game Center应用并直接进入我的应用程序的“页面”。 - pyrosphere
另一个原因:如果用户尚未登录Game Center并尝试访问您的应用程序中需要Game Center的功能,则将他们引导到Game Center应用程序以进行登录可能会很有帮助。 - codeperson
3个回答

26

我尝试了许多不同的组合。从 iBook 缺乏这样一个功能、缺乏文档以及你肯定发现的缺乏在互联网上的信息来看,我想说如果它被设置为完全通过 URL 进入各个应用程序,那么可能需要有人去暴力破解 URL 以弄清楚它是如何工作的。以下是我尝试的一些组合:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:id350536422"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:us/app/cheese-moon/id350536422"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:games/"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:350536422"]];

更新

我仔细研究了操作系统的内部结构,并找到了游戏中心的URL解析模式:

游戏中心的URL解析模式

你需要熟练掌握正则表达式才能使用它们。这里有一些我为你打出来的:

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:/me/account"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:/me/signout"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:/friends/recommendations"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:/games/recommendations"]];

1
深思熟虑。打开特定游戏的Game Center最可能的URL是:^/games/game/.+,但我尝试了所有我能想到的东西,比如gamecenter:/games/game/cut-the-rope或带有ID的内容,但都没有成功。 - pyrosphere
如何在iOS7中使其工作。在iOS7中,您必须转到“设置”应用程序才能从Game Center注销。是否有一个URL方案可以带我们到设置页面? - Him
@他 我还没有在iOS7上检查过这个。如果我这么做了,我会回复的。 - james_womack

0
Cirrostratus的回答中使用的示例URL缺少一些内容。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter://static.gc.apple.com/me/"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter://static.gc.apple.com/friends/"]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter://static.gc.apple.com/games/"]];

这些URL在iOS 6和7上似乎对我有效。我假设如果您已经登录了沙盒Game Center帐户,那么您必须使用sandbox.gc.apple.com。我尝试通过/games/game/<id>//friends/player/<id>/访问特定的游戏或朋友页面,但是任何我尝试的ID都似乎无法工作。对于朋友的URL,我进入了一个空白的朋友页面。

即使有人找到了解决方法,由于这是未记录的,苹果公司将来随时可能更改,因此我不会将这样的URL硬编码到应用程序中。


0

只使用这个例程。

    - (void)showGameCenter
{

GKGameCenterViewController *gameCenterController = [[GKGameCenterViewController alloc] init];

    if (gameCenterController != nil)
    {
        gameCenterController.gameCenterDelegate = self;
        gameCenterController.viewState = GKGameCenterViewControllerStateDefault;       
        [self presentViewController: gameCenterController animated: YES completion:nil];

    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接