Game Center URL scheme

2019-02-02 00:02发布

It's possible to open the Game Center app from your own app using:

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

Is there a way to open it on the page for a specific game?

3条回答
别忘想泡老子
2楼-- · 2019-02-02 00:34

I've tried many different combinations. Judging by iBook's lack of such a feature, the lack of documentation and as I'm sure you've found—the lack of info on the internet—I'm going to say that someone'd probably have to either brute force the URL to figure it out (if it's set up to go to individual apps by URL at all). Here are some I've tried:

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

UPDATE

I combed through the internals of the OS and found out the URL resolution patterns for Game Center:

URL resolution patterns for Game Center

You'll need to be savvy with regex to use all of them. Here are some I've typed out for you:

    [[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"]];
查看更多
Deceive 欺骗
3楼-- · 2019-02-02 00:55

The example URLs used in Cirrostratus's answer are missing a few bits.

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

These URLs seem to work for me on iOS 6 and 7. I'm assuming if you were signed into a sandbox Game Center account that you'd have to use sandbox.gc.apple.com instead. I tried to go to a specific game or friend page via /games/game/<id>/ and /friends/player/<id>/ but anything I try for ID doesn't seem to work. For the friends URL I go to a blank friend page.

Even if someone did figure it out, because it's undocumented Apple could change at any time in the future so I wouldn't hardcode a URL like this into an app.

查看更多
▲ chillily
4楼-- · 2019-02-02 00:56

Only use this routine .

    - (void)showGameCenter
{

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

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

    }
}
查看更多
登录 后发表回答