我在看Apple的Lister (for Apple Watch, iOS, and OS X)样本。样本执行测试iOS和OS X:Apple Watch的预处理器宏?
#import <TargetConditionals.h>
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
@import ListerKit;
#elif TARGET_OS_MAC
@import ListerKitOSX;
#endif
然而,没有试验TARGET_OS_WATCH
或类似。 Grepping在TargetConditionals.h
watch
提供没有命中:
$ cat /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
/SDKs/iPhoneOS7.1.sdk/usr/include/TargetConditionals.h | grep -i watch
$
从TargetConditionals.h
,我知道的有:
These conditionals specify in which Operating System the generated code will run. The MAC/WIN32/UNIX conditionals are mutually exclusive. The EMBEDDED/IPHONE conditionals are variants of TARGET_OS_MAC. TARGET_OS_MAC - Generate code will run under Mac OS TARGET_OS_WIN32 - Generate code will run under 32-bit Windows TARGET_OS_UNIX - Generate code will run under some non Mac OS X unix TARGET_OS_EMBEDDED - Generate code will run under an embedded OS variant of TARGET_OS_MAC TARGET_OS_IPHONE - Generate code will run under iPhone OS which is a variant of TARGET_OS_MAC. TARGET_IPHONE_SIMULATOR - Generate code for running under iPhone Simulator
问题:有没有苹果的手表预处理器?
我与ios标记,但我不知道这是对这个问题的正确操作系统。
下面的列表是从iPhone的TargetConditionals.h
编译。模拟器和OS X是相似的(他们只是有不同的位设置为1):
#define TARGET_OS_MAC 1
#define TARGET_OS_WIN32 0
#define TARGET_OS_UNIX 0
#define TARGET_OS_EMBEDDED 1
#define TARGET_OS_IPHONE 1
#define TARGET_IPHONE_SIMULATOR 0
问题:是否手表使用TARGET_OS_EMBEDDED
?手表省略TARGET_OS_IPHONE
?
你可以有一个共享管理器类,调用[UIApplication sharedApplication],这是禁止在手表上,但你知道永远不会被调用或可能想要使用此宏覆盖。 – ge0rges