Mat*_*oal 5 xcode objective-c ios swift tvos
我已经将一个 iOS 应用程序“移植”到 Apple TV 上,因为我真的想尽可能共享资源,所以我不得不将一些代码行用于 iOS,将一些其他代码行用于 TVOS。我试过类似的东西:
#if TARGET_OS_TV
Run Code Online (Sandbox Code Playgroud)
和
#if TARGET_OS_IOS
Run Code Online (Sandbox Code Playgroud)
但是当我在 iOS 或电视模拟器上启动应用程序时,此代码不起作用。我以为 iPhone 模拟器只是在TARGET_OS_IOS...下执行代码,但我错了。哪个是针对 iOS 和 TV 操作系统保留模拟器正确执行的最佳方法?
我可能需要的代码示例是:
#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
Run Code Online (Sandbox Code Playgroud)
对于像我一样寻找平台宏的人。
在 ObjC 中TARGET_OS_IOS用于 iOS 和TARGET_OS_TVtvOS 如下:
#if TARGET_OS_IOS
/// [something doIOS];
#elif TARGET_OS_TV
/// [something doTVOS];
#else
/// Perhaps watchOS or macOS?
#endif
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2574 次 |
| 最近记录: |