Prevent certain code from compiling?

Robert PaulsonRobert Paulson Posts: 492Registered Users
edited December 2010 in iOS SDK Development

we want to implement Game Center in our app but also want to make the app available for users with iOS versions that don't support GC (we have an alternative solution there).

We don't understand, however, how we can compile versions for, say, 3.2 and 4.1 given the same code.

This site suggests something like this:
#if __IPHONE_3_0
    // Statement for SDK 3.0
    // Statement for older OS versions

On Apple's site, I found this method:
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);

I feel like I have to combine these two approaches but can't figure out how. If I try to compile for version 3.2, xcode complains that it doesn't know GKLocalPlayer. Which, of course, makes sense. How can I prevent it from trying to run the code containing GKLocalPlayer etc. when compiling for older versions?

Thanks a lot for any hints!

Post edited by Robert Paulson on
<i>We are GodÂ’s middle children, according to Tyler Durden, with no special place in history and no special attention.</i><br />
<br />
Consider saying <i>thanks</i> by buying <a href="" target="_blank">my app</a>. :]


Sign In or Register to comment.

Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!