I've "ported" an iOS App to Apple TV and since I really wanted to share as resources as possible I had to target some lines of code for iOS and some others to TVOS. I've tried with something like:
#if TARGET_OS_TV
and
#if TARGET_OS_IOS
but when I launch the apps on iOS or TV simulator this code doesn't work. I thought that iPhone simulator just executes the code under TARGET_OS_IOS
... but I was wrong. Which is the best way to target iOS and TV os preserving simulators correct execution?
An example of the code that I might need is:
#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
For someone looking for platform macro as me.
In ObjC use
TARGET_OS_IOS
for iOS andTARGET_OS_TV
for tvOS as next: