Preprocessor macro for Apple Watch?

前端 未结 4 1945
南旧
南旧 2021-02-19 11:49

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 

#if          


        
4条回答
  •  礼貌的吻别
    2021-02-19 12:41

    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

提交回复
热议问题