★ TouchArcade needs your help. Click here to support us on Patreon.

Running Game Center app on 3.x?

11-09-2010, 01:22 AM
#1
Joined: Feb 2009
Location: San Jose, CA
Posts: 546
Running Game Center app on 3.x?

I'd like to include Game Center support for devices with iOS 4.1 or higher. As far as I can tell, the only way I can compile using the GameKit classes is with Base SDK 4.1. When I select Base SDK 3.X, even with the GameKit framework included, my app will no longer compile because the GK classes are missing.

My question is: if I compile with the 4.1 SDK, will 3.X devices be able to run the application (minus the Game Center support, of course)? Since I don't have a 3.X device, I have no way to really test if it works or not. I'd like to make sure 3.X is supported since a lot of people haven't upgraded, but I also want to include Game Center support for devices that have it.
11-09-2010, 02:49 AM
#2
Base SDK is what you link against. You want that to be 4.1. iOS deployment target is the minimum system requirement, you'd want that at 3.0.

You'll need to weak link the gamecenter framework, and check the OS version before calling any of the functions.


NSArray* versionComponents = [[UIDevice currentDevice].systemVersion componentsSeparatedByString:@"."];
NSString* majorVersionString = (NSString*)[versionComponents objectAtIndex:0];
int majorVersionNumber = [majorVersionString intValue];
if (majorVersionNumber > 3) {
if (majorVersion == 4) {
// you probably want to check to see if the array has at least two values.
NSString* minorVersionString = (NSString*)[versionComponents objectAtIndex:1];
int minorVersionNumber = [minorVersionString intValue];
if (minorVersion > 0) mSupportsGameCenter = true;
}
else {
mSupportsGameCenter = true;
}
}

Last edited by Golden Hammer; 11-09-2010 at 02:56 AM. Reason: oops forgot gamecenter was 4.1, not 4.0
11-09-2010, 02:49 AM
#3
Joined: Dec 2009
Posts: 293
If you weak reference GameKit, than you can compile against 4.1 and run at 3.X. You need to set the target version to 3.0 though.

In GameCenter codes side, if you use OpenFeint for integration, you don't have to do anything but if you reach GameCenter directly using your own codes, you need to check whether you can create GameKit classes or if the iOS version is 4.1 and higher and than run these codes so your game don't get crashed on 3.X devices.
11-09-2010, 03:40 AM
#4
Joined: Feb 2009
Location: San Jose, CA
Posts: 546
Ahhh -- I had read about the weak linking, but I totally missed the deployment target. I assumed if I set the BaseSDK version that it would require the target device to have that version too. I do see the 'Deployment Target' now, in the build settings. Makes total sense.

Thanks a bunch for the help!