21

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?

pyrosphere
  • 418
  • 3
  • 9
  • What is it you want to do beyond using the normal GameKit interactions outlined here? http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/LeaderBoards/LeaderBoards.html#//apple_ref/doc/uid/TP40008304-CH6-SW13 – brindy Jul 23 '11 at 00:24
  • While it's possible to show leaderboards and achievements inside the app, I would have liked the ability to open the actual Game Center app from a button and directly go to the "page" for my app. – pyrosphere Jul 28 '11 at 11:33
  • Another reason: if the user is not logged into Game Center and is trying to access a feature in your app that requires it, it might be helpful to direct them to the Game Center app to log in. – codeperson Feb 28 '12 at 01:40

3 Answers3

26

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"]];
james_womack
  • 10,028
  • 6
  • 55
  • 74
  • 1
    Insightful. The most probable URL to open Game Center for a specific game would be: ^/games/game/.+ however I threw everything I could think of like gamecenter:/games/game/cut-the-rope or with IDs and nothing worked. – pyrosphere Nov 07 '11 at 14:34
  • How to make this work in iOS7. In iOS7, you have to go to the Settings app to log out from Game Center. Is there a url scheme that takes us to the Settings page? – Him Oct 15 '13 at 11:26
  • @Him I haven't checked this out in iOS7 yet. If I do, I'll post back. – james_womack Oct 16 '13 at 17:08
0

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.

Brian Teschke
  • 86
  • 1
  • 3
0

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

    }
}
kleopatra
  • 51,061
  • 28
  • 99
  • 211