Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-28061] TiAPI: Add OS version major/minor integer constants

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2020-08-18T15:28:57.000+0000
Affected Version/sn/a
Fix Version/sRelease 9.2.0
ComponentsAndroid, iOS
Labelsandroid, iOS, os, platform, version
ReporterJoshua Quick
AssigneeJoshua Quick
Created2020-08-01T03:33:55.000+0000
Updated2020-08-26T14:38:47.000+0000

Description

*Summary:* Currently, you can only fetch the OS version as a string via the [Ti.Platform.version](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Platform-property-version) property. This is not convenient to use when you only want to call APIs on higher OS versions. For example, we've seen a lot of code that looks like the below.
if (OS_IOS && parseInt(Ti.Platform.version.split('.')[0]) >= 13) {
	// Do something on iOS 13 or higher...
}
*Feature Proposal:* Add the following properties to Ti.Platform... * Ti.Platform.versionMajor // Returns an integer. * Ti.Platform.versionMinor // Returns an integer. Also add the following global constants. _(These will pair well with [OS_ANDROID](https://docs.appcelerator.com/platform/latest/#!/api/Global-property-OS_ANDROID) and [OS_IOS](https://docs.appcelerator.com/platform/latest/#!/api/Global-property-OS_IOS).)_ * OS_VERSION_MAJOR * OS_VERSION_MINOR This will make the above code example look simpler like this...
if (OS_IOS && (OS_VERSION_MAJOR >= 13)) {
	// Do something on iOS 13 or higher...
}
*Note:* On Android, we have a [Ti.Platform.Android.API_LEVEL](https://docs.appcelerator.com/platform/latest/#!/api/Titanium.Platform.Android-property-API_LEVEL) constant which is a single integer used to represent all Android OS versions. It's best to use this if you can, but note that no other platform has a similar concept... while all operating system support a <major>.<minor> version that we can use for parity. https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels

Comments

  1. Joshua Quick 2020-08-01

    PR (master): https://github.com/appcelerator/titanium_mobile/pull/11859
  2. Christopher Williams 2020-08-05

    merged to master for 9.2.0 target. Auto-backport PR for 9_3_X is in-process: https://github.com/appcelerator/titanium_mobile/pull/11869
  3. Samir Mohammed 2020-08-18

    FR Passed, Tested using the test case mentioned in this PR https://github.com/appcelerator/titanium_mobile/pull/11859 tested in with the SDK versions 9.2.0.v20200814104443 and 9.3.0.v20200814072212. Test and other information can be found at: https://github.com/appcelerator/titanium_mobile/pull/11859 https://github.com/appcelerator/titanium_mobile/pull/11869 *Test Environment*
       MacOS Big Sur: 11.0 Beta 4
       Xcode: 12.0 Beta  4 
       Java Version: 1.8.0_242
       Android NDK: 21.3.6528147
       Node.js: 12.18.1
       ""NPM":"5.0.0","CLI":"8.1.0-master.11""
       iphone 8 Sim (14.0 Beta)
       API29 Pixel XL emulator
       

JSON Source