Game Center URL scheme

2019-02-02 00:49发布

问题:

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?

回答1:

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:

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


回答2:

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.



回答3:

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

    }
}