Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find the Deployment Target at runtime of a framework that I can't recompile

It's pretty straight-forward to determine the Deployment Target for an app at compile time with the macro __IPHONE_OS_VERSION_MIN_REQUIRED. It's also straight-forward to find the current iOS version the app is running on at runtime. I'm trying to figure out the deployment target of an app at runtime. I need to use this in a framework that's already compiled. Is there a public API method to determine this? I'm not able to find one.

Just to be clear. I'm looking to get the Deployment Target for an iOS app at runtime from my framework. NOT compile time. In my framework I need to alert the user of the framework that certain features will not work if their deployment target is too far back.

I get that is easy to do while compiling but my framework is already compiled and I don't want to require the user of the framework to add a macros to their code for my framework to determine their deployment target.

like image 858
ScottWasserman Avatar asked Nov 10 '22 03:11

ScottWasserman


1 Answers

This is an old question, but I just verified the answer so here goes:

On iOS, you should be using the MinimumOSVersion key in the Info.plist to find the minimum supported version at runtime.

The source is actually linked from the documentation that Josh Caswell posted, about LSMinimumSystemVersion.

Note that the documentation it explains that you, as the developer, should not set the MinimumOSVersion value yourself, and that this is auto-populated for you by Xcode during a build. This explains the rather cryptic "Do Not Use" in another part of this documentation.

Posting the description of this key here, for posterity (December 2016), in case the documentation changes:

MinimumOSVersion (String - iOS). When you build an iOS app, Xcode uses the iOS Deployment Target setting of the project to set the value for the MinimumOSVersion key. Do not specify this key yourself in the Info.plist file; it is a system-written key. When you publish your app to the App Store, the store indicates the iOS releases on which your app can run based on this key. It is equivalent to the LSMinimumSystemVersion key in macOS.

I verified this by printing out the value in a test app (and changing the Xcode project's Deployment target to different values:

if let infoPlist = Bundle.main.infoDictionary {
  let minimumVersion = infoPlist["MinimumOSVersion"]
  if let minimumVersion = minimumVersion {
    print("Minimum version is \(minimumVersion)")
  }
}
like image 196
Rizwan Sattar Avatar answered Dec 06 '22 09:12

Rizwan Sattar