I have a piece of code to change calls between different platforms. But I have detected a problem using iphone and ipad, TARGET_OS_IPHONE definition only works with iphone, but no ipad, I don´t want to try using else to think is ipad because maybe in the future this will be a source of problems.
I have lost 2 days looking for a problem with colors in opencv matrix caused by this.....
My question, exist a proper solution official to execute a piece of code in iOS S.O (Iphone AND Ipad)?
As reference, I look always in this link.
An example to select code:
#ifdef __linux__
// All linux arch
#elif _WIN32
// Windows 32 and 64
#elif __APPLE__
#ifdef TARGET_OS_IPHONE
// iOS, no work with iPAD
#elif TARGET_IPHONE_SIMULATOR
// iOS Simulator
#elif TARGET_OS_MAC
// Other kinds of Mac OS
#else
// Unsupported platform
#endif
#elif __ANDROID__
// Android all versions
#else
// Unsupported architecture
#endif
Try including "TargetConditionals.h" file in case of '__APPLE__'. This file includes all the macros refered to the Apple devices.
Any way, using your example, the correct way should be:
#ifdef __linux__
// All linux arch
#elif _WIN32
// Windows 32 and 64
#elif __APPLE__
#include "TargetConditionals.h" // <--- Include this
#ifdef TARGET_OS_IOS // <--- Change this with a proper definition
// iOS, including iPhone and iPad
#elif TARGET_IPHONE_SIMULATOR
// iOS Simulator
#elif TARGET_OS_MAC
// Other kinds of Mac OS
#else
// Unsupported platform
#endif
#elif __ANDROID__
// Android all versions
#else
// Unsupported architecture
#endif
Also, you can let 'TARGET_OS_IPHONE' definition there, but 'TARGET_OS_IOS' is more appropiate.
You can include this file directly, or you can find it in your disk following the path: '/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS.sdk/usr/include/TargetConditionals.h'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With