Game Development Reference
In-Depth Information
Once the iOS build runs successfully, select the LearnSpriteBuilder Android scheme and
an Android device. Again, refer to Figure 13-11 . Try to run the project. If you used one of
the projects provided with the topic instead of creating your own project, the build may
fail a bit earlier. The abbreviated error message will be:
Prefix.pch:12:9: 'UIKit/UIKit.h' file not found
The UIKit framework is not available on Android since Android uses a completely differ-
ent user interface framework. However, I can't remember making any reference to UIKit
classes anywhere. It turns out that the UIKit reference is included by Xcode projects cre-
ated by earlier versions of SpriteBuilder. In the latest SpriteBuilder v1.3 beta, there is no
reference to UIKit anymore.
Alas, if you need to fix this or similar issues with iOS framework headers, you will have
to use a platform-specific macro to prevent the iOS framework header from being impor-
ted on any platform except iOS. Update the Prefix.pch file, which is in the Supporting
Files group so that it looks like the one in Listing 13-4 (changes highlighted).
Listing 13-4 . Avoid importing the UIKit header when the build target isn't iOS
#import <Availability.h>
#ifdef __OBJC__
#if __CC_PLATFORM_IOS
#import <UIKit/UIKit.h>
#endif
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "cocos2d-ui.h"
#endif
There are three macros provided by Cocos2d that allow you to include or exclude code
from building, depending on the target platform:
__CC_PLATFORM_IOS
__CC_PLATFORM_MAC
__CC_PLATFORM_ANDROID
Only one macro holds the value 1 (is true ) when building for a specific platform. The
others will evaluate to false . A typical switch between iOS and Android-specific code
would look like that shown in Listing 13-5 .
Search WWH ::




Custom Search