Integrating Game Center in Cocos2d

Forums Programming high score, social and ads networks Integrating Game Center in Cocos2d

This topic contains 12 replies, has 9 voices, and was last updated by  kups 1 year, 11 months ago.

Viewing 13 posts - 1 through 13 (of 13 total)
Author Posts
Author Posts
September 19, 2011 at 2:24 am #235357

cb31416
Participant
@cb31416

I been trying to integrate Game Center in my game for the past 2 days, but I keep getting “This game is not recognized by Game Center” in the Simulator as well as in the device.

I created a new Cocos2d project (using the Cocos2d template) and added this Game Center helper class (from raywenderlich.com tutorial). Here is the code for the class that I added to my clean Cocos2d project:

//
// GCHelper.h
//
//
//
//
//

#import <Foundation/Foundation.h>
#import <GameKit/GameKit.h>

@interface GCHelper : NSObject
{
BOOL gameCenterAvailable;
BOOL userAuthenticated;
}

@property (assign, readonly) BOOL gameCenterAvailable;

+ (GCHelper *)sharedInstance;
- (void)authenticateLocalUser;

@end

//
// GCHelper.m
//
//
//
//
//

#import "GCHelper.h"

@implementation GCHelper
@synthesize gameCenterAvailable;

#pragma mark Initialization

static GCHelper *sharedHelper = nil;

+ (GCHelper *) sharedInstance
{
if (!sharedHelper)
{
sharedHelper = [[GCHelper alloc] init];
}
return sharedHelper;
}

- (BOOL)isGameCenterAvailable
{
// check for presence of GKLocalPlayer API
Class gcClass = (NSClassFromString(@"GKLocalPlayer"));

// check if the device is running iOS 4.1 or later
NSString *reqSysVer = @"4.1";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
BOOL osVersionSupported = ([currSysVer compare:reqSysVer
options:NSNumericSearch] != NSOrderedAscending);

return (gcClass && osVersionSupported);
}

- (id)init
{
if ((self = [super init]))
{
gameCenterAvailable = [self isGameCenterAvailable];

if (gameCenterAvailable)
{
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
[nc addObserver:self
selector:@selector(authenticationChanged)
name:GKPlayerAuthenticationDidChangeNotificationName
object:nil];
}
}
return self;
}

- (void)authenticationChanged
{

if ([GKLocalPlayer localPlayer].isAuthenticated && !userAuthenticated)
{
NSLog(@"Authentication changed: player authenticated.");
userAuthenticated = TRUE;
}
else if (![GKLocalPlayer localPlayer].isAuthenticated && userAuthenticated)
{
NSLog(@"Authentication changed: player not authenticated");
userAuthenticated = FALSE;
}

}

#pragma mark User functions

- (void)authenticateLocalUser
{

if (!gameCenterAvailable) return;

NSLog(@"Authenticating local user...");
if ([GKLocalPlayer localPlayer].authenticated == NO)
{
[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:nil];
}
else
{
NSLog(@"Already authenticated!");
}
}
@end

And added this to the AppDelegate.m

#import "GCHelper.h"

// At the end of applicationDidFinishLaunching, right before
// the last line that calls runWithScene:
[[GCHelper sharedInstance] authenticateLocalUser];

Here are some screen shots of how I made the App ID, and how I added the application to iTunes Connect:

Creating the App ID:

Creating the Provisioning Profile:

Adding the app in iTunes Connect:

App information was created:

Enabling Game Center:

Enabling Game Center in Current Version:

Setting the Bundle Identifier in XCODE:

And when I run the application this is what I get:

I have read hundreds of posts and the solutions in these posts is either:

- Do a Clean in XCODE.

- Delete app from device and reinstall it.

- Make sure you are using the correct Bundle Identifier.

I have tried all those and I still get “This game is not recognized by Game Center” in simulator and device.

I’m not using a jailbroken device either.

Any help will be gretely appreciated.

September 19, 2011 at 6:26 am #347982

jandujar
@jandujar

have you wait 24 hours after you enabled the gamecenter? I don’t remember, but I think I had the same situation some months ago.

September 19, 2011 at 7:43 am #347983

itlgames
Moderator
@itlgames

Yeah, wait 24 hours at least, and weekends don’t count.

September 19, 2011 at 1:15 pm #347984

cb31416
Participant
@cb31416

@jandujar @itlgames I haven’t wait 24hrs after I enabled Game Center in iTunes Connect, I tried all day Saturday and all day Sunday, but if weekends don’t count that could be the reason I get that error. I hope that’s my problem.

I tried Apple example GKTapper and that worked, but I didn’t have to set anything in iTunes Connect for that example since that’s already setup by Apple.

I’m going to wait the 24 hrs. and I’ll update if that resolved my problem.

Thanks guys.

September 19, 2011 at 9:08 pm #347985

kiles
@kiles

Working 4 me after wait 1 day

September 19, 2011 at 9:30 pm #347986

rrdz473
@rrdz473

if your phone is jailbroken it wont work, try a diff phone if it is

EDIT: sorry , i hadnt seen where you had posted that it wasnt jailbroken. Im having a similar issue. the difference is that mine doesnt list the achievemnents or leaderboards.

September 20, 2011 at 12:30 pm #347987

cb31416
Participant
@cb31416

Game Center is now working for me, waiting the 24 hrs (not counting weekends) fixed my problem of “This game is not recognized by Game Center.” I wish I new the 24 hrs thing before I wasted two full days looking for the problem and pulling my hair :)

September 20, 2011 at 1:58 pm #347988

jd
Participant
@jd

Computers don’t work on the weekend.

September 20, 2011 at 3:37 pm #347989

cb31416
Participant
@cb31416

@jd apparently they don’t work on weekends :) and neither sometimes on weekdays. No I’m getting a message “Could not connect to Game Center server.”

September 20, 2011 at 3:41 pm #347990

MikeSz
Participant
@mikesz

Same problem since the morning, GC Sanbox is broken again

September 20, 2011 at 3:45 pm #347991

Normal Force
@normal-force

They do it so you can test how your app will respond when the network is up and down.

>.> <.<

September 20, 2011 at 3:58 pm #347992

jd
Participant
@jd

Apple makes billions of dollars, yet they don’t have support on weekends and their test environment is garbage. Game Center is very frustrating to test in Sandbox. I feel your pain as I lost weeks upon weeks trying to get my code to work when it was on their end the entire time.

May 9, 2012 at 11:41 am #347993

kups
@kups

Hi im new to cocos2d…i tried everything as mentioned above..but it gives linking erros like

Undefined symbols for architecture i386:

“_OBJC_CLASS_$_GKLocalPlayer”, referenced from:

objc-class-ref in GCHelper.o

“_GKPlayerAuthenticationDidChangeNotificationName”, referenced from:

-[GCHelper init] in GCHelper.o

ld: symbol(s) not found for architecture i386

collect2: ld returned 1 exit status

please help me……

Viewing 13 posts - 1 through 13 (of 13 total)

You must be logged in to reply to this topic.