I was looking at Apple's Lister (for Apple Watch, iOS, and OS X) sample. The sample performs a test for iOS and OS X:
#import <TargetConditionals.h>
#if (TARGET_OS_IPHONE || TARGET_IPHONE_SIMULATOR)
@import ListerKit;
#elif TARGET_OS_MAC
@import ListerKitOSX;
#endif
However, there is no test for TARGET_OS_WATCH
or similar. Grepping for watch
in TargetConditionals.h
delivers no hits:
$ cat /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
/SDKs/iPhoneOS7.1.sdk/usr/include/TargetConditionals.h | grep -i watch
$
From TargetConditionals.h
, I know there are:
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
Question: Is there a preprocessor for Apple's watch?
I'm tagging with ios, but I'm not sure that's the correct OS for this question.
The list below was compiled from iPhone's TargetConditionals.h
. The Simulator and OS X are similar (they just have different bits set to 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
Questions: Does the watch use TARGET_OS_EMBEDDED
? Does the watch omit TARGET_OS_IPHONE
?
This helps your Apple Watch determine if you’re moving, how much you’re moving, and then calculate calorie usage. To double-check that Wrist Detection is turned on, open the Apple Watch app on your iPhone.
One of the most important things to check is that the Wrist Detection setting on your Apple Watch is turned on. This helps your Apple Watch determine if you’re moving, how much you’re moving, and then calculate calorie usage. To double-check that Wrist Detection is turned on, open the Apple Watch app on your iPhone.
It’s important to have excellent GPS signal during the calibration process. Open the Workout app, and choose “Outdoor Walk” as your activity. You’ll then walk at your regular pace for 20 minutes. This exercise will help your Apple Watch understand your pace, acceleration, stride, and thus refine the calculations of your calorie burn.
This light-weight accessory is a fantastic tool for those trying to manage their fitness and activity. Fortunately, the Apple Watch can help you reach your goals in a number of ways, including serving as a handy calorie counter.
You can find all kind of target conditionals in the TargetConditionals.h (cmd + shift + o and type TargetConditionals.h).
In this list you can find a list like this and many more useful defines. Currently it does contain TARGET_OS_WATCH since WatchOS 2. For WatchOS 1 it was not possible to run custom code on the watch so it was not needed back then since everything ran on the phone itself.
#define TARGET_OS_MAC 1
#define TARGET_OS_WIN32 0
#define TARGET_OS_UNIX 0
#define TARGET_OS_IPHONE 1
#define TARGET_OS_IOS 0
#define TARGET_OS_WATCH 1
#define TARGET_OS_TV 0
#define TARGET_OS_SIMULATOR 0
#define TARGET_OS_EMBEDDED 1
Swift Addition
#if os(watchOS)
[Watch code]
#else
[Code for iOS, appleTV, or any else clause]
#endif
Some other valid values: iOS, OSX, tvOS
A small explanation about this and more http://nshipster.com/swift-system-version-checking/
At the bottom of this document https://developer.apple.com/library/ios/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithCAPIs.html#//apple_ref/doc/uid/TP40014216-CH8-XID_15#Build Configurations Under the section 'Build Configurations' you can find a (hopefully) up to date list with all these values that are currently available
As of watchOS 2.0, you can run native code on the watch, so this is a more relevant question.
I'm using the first early beta of watchOS 2, so this may change, but right now, TARGET_OS_WATCH
is set to 1 on watchOS.
(Also, be careful: TARGET_OS_IPHONE
is also set to 1 on watchOS, though TARGET_OS_IOS
is 0.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With