Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TARGET_OS_IOS, TARGET_OS_TV and simulators

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
like image 710
MatterGoal Avatar asked Dec 20 '16 15:12

MatterGoal


1 Answers

For someone looking for platform macro as me.

In ObjC use TARGET_OS_IOS for iOS and TARGET_OS_TV for tvOS as next:

#if TARGET_OS_IOS
    /// [something doIOS];
#elif TARGET_OS_TV
    /// [something doTVOS];
#else
    /// Perhaps watchOS or macOS?
#endif
like image 123
ManWithBear Avatar answered Oct 07 '22 09:10

ManWithBear