Will #if __IPHONE_4_0 work on iPad?
Will this check work on the iPad as well as iPhone? I guess I am just confused about using the term “iPhone” on an iPad. Is there something else I need to check for iPad OS version or does the macro refer to the general iOS version.
#if __IPHONE_4_0 // Do stuff #elif __IPHONE_3_0 // Do 3.0 stuff #endif
- How to disable the “drag down to view Notifications” feature?
- How to create 1536x2048 framebuffer for iPad Retina sample (GLGravity)
- Disable Dictation button on the keyboard of iPhone 4S / new iPad
- Frozen uptime on iOS / iPhone
- How can I find the UIPopoverController from the UIViewController being displayed in a popover?
- Can I re-open .xcarchive on Xcode?
2 Solutions Collect From Internet About “Will #if __IPHONE_4_0 work on iPad?”
The problem with
__IPHONE_3_0 and the like is that they are defined even if targeting other iOS versions; they are version identification constants, not constants that identify the target iOS version. Use
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0 #elif __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0 #else #endif
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000 #elif __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000 #else #endif
to get around the bug mentioned in the comments for “How to target a specific iPhone version?”
__IPHONE_OS_VERSION_MAX_ALLOWED might also be of use, in limited circumstances.
And, yes, it doesn’t matter what device the app will run on. These constants are defined by the compiler and don’t exist on the devices. Once the pre-processor runs, no macros are left. Though there are differences in the devices themselves, the iPhone and iPad both run iOS, and that’s what you’re really targetting.
The code you posted is a compiler directive. This means that it will not run on iPad or iPhone. It is handled when you build your app binary. Incidentally, if you’re building for iPad, then you are building for 3.2, not 3.0 or 4.0.
If you use 3_2 or 4_2 instead of 3_0 or 4_0 it should work.
- What is the difference and purpose of auto and escaping closure in Swift?
- perform segue with identifier wont work in swift 2
- Are view controllers with nib files broken in ios 8 beta 5?
- Can I extend a final class in Swift?
- Using OpenSSL cocoa pod in iOS project
- PresentScene only working without transition over a collection view
- how to find out error Running command – failed! Exception: Using cordova-fetch for cordova-ios@~4.4.0
- Swift Firebase Snapshot to object model
- can't find /var/mobile/applications directory for ios documents
- Is it possible to upload to App Store using Xcode 9 GM?
- Realm Swift 0.92.3 “Run Script Phase” not working
- Exception Breakpoint in Xcode
- OSX Mac App Store: how to install a daemon shell script
- Sscanf Equivalent in Objective-C
- Undefined symbols for architecture i386: “_utf8_nextCharSafeBody”, referenced from:”