TARGET_OS_IOS、TARGET_OS_TV 和模拟器

TARGET_OS_IOS, TARGET_OS_TV and simulators

我有 "ported" Apple TV 的 iOS 应用程序,因为我真的想作为 possible 共享资源,所以我不得不针对 iOS 和其他一些人到 TVOS。 我试过类似的东西:

#if TARGET_OS_TV

#if TARGET_OS_IOS

但是当我在 iOS 或电视模拟器上启动应用程序时,此代码不起作用。我以为 iPhone 模拟器只是执行 TARGET_OS_IOS 下的代码......但我错了。哪个是目标 iOS 和电视 os 保持模拟器正确执行的最佳方式?

我可能需要的代码示例是:

#if TARGET_OS_IOS 
    DoSomethingWithiOS() // This should work also on iOS sim
#elseif TARGET_OS_TV
    DoSomethingWithOSTV() // This should work also on TV sim
#endif

对于像我一样寻找平台宏的人。

在 ObjC 中,iOS 使用 TARGET_OS_IOS,下一个 tvOS 使用 TARGET_OS_TV

#if TARGET_OS_IOS
    /// [something doIOS];
#elif TARGET_OS_TV
    /// [something doTVOS];
#else
    /// Perhaps watchOS or macOS?
#endif