游戏中心URL方案

时间:2011-06-03 10:57:15

标签: ios game-center

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

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"gamecenter:"]];

有没有办法在特定游戏的页面上打开它?

3 个答案:

答案 0 :(得分: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"]];

<强>更新

我梳理了操作系统的内部,并找到了Game Center的URL解析模式:

URL resolution patterns for Game Center

你需要精通正则表达式才能使用所有这些。以下是我为你输入的一些内容:

    [[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 :(得分:0)

Cirrostratus的答案中使用的示例网址缺少一些内容。

[[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/"]];

这些网址在iOS 6和7上似乎对我有用。我假设您已登录沙盒游戏中心帐户,而您必须使用sandbox.gc.apple.com。我尝试通过/games/game/<id>//friends/player/<id>/访问特定的游戏或朋友页面,但我尝试使用ID的任何内容似乎都无效。对于朋友网址,我会转到一个空白的朋友页面。

即使有人确实弄清楚了,因为它是未记录的,Apple可能会在将来的任何时候改变,所以我不会将这样的URL硬编码到应用程序中。

答案 2 :(得分:0)

仅使用此例程。

    - (void)showGameCenter
{

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

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

    }
}