How to programmatically determine the Game Center?

I am adding Game Center support to my game. Since my game can run on versions of iOS prior to version 3.0, I want it to leave a backup only to save achievements and leaders at the local level in the absence of Game Center.

Now I have this:

+ (BOOL) isGameCenterAvailable { Class playerClass = NSClassFromString( @"GKLocalPlayer" ); if( playerClass != nil && [playerClass localPlayer] != nil ) { DebugLog( @"Game Center is available" ); return YES; } DebugLog( @"Game Center is NOT available" ); return NO; } 

However, this does not seem to work at all. Firstly, despite the GKLocalPlayer link , indicating that this class is available in iOS 4.1 and higher, the above test passes in iOS 4.0 (I didn’t try to use earlier versions). On the other hand, the test also passes on devices with iOS 4.1, but which otherwise do not support Game Center (for example, iPhone 3G).

I went through various GameKit and Game Center games on the Internet, and I could not figure it out. I could, of course, determine the OS version, but that seems lame. It would also not help with unsupported hardware (e.g. 3G). It can also be detected, I suppose, but again, it seems, succinctly.

What is the “right path” for software detection for Game Center support?

+4
source share
1 answer

This is the code provided in the GameKit documentation on the Apple website:

 BOOL isGameCenterAvailable() { // Check for presence of GKLocalPlayer API. Class gcClass = (NSClassFromString(@"GKLocalPlayer")); // The device must be running 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); } 

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/GameCenterOverview/GameCenterOverview.html%23//apple_ref/doc/uid/TP40008304-CH5-SW7

+11
source

All Articles