[TIMOB-28061] TiAPI: Add OS version major/minor integer constants
| GitHub Issue | n/a |
|---|---|
| Type | New Feature |
| Priority | Low |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2020-08-18T15:28:57.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 9.2.0 |
| Components | Android, iOS |
| Labels | android, iOS, os, platform, version |
| Reporter | Joshua Quick |
| Assignee | Joshua Quick |
| Created | 2020-08-01T03:33:55.000+0000 |
| Updated | 2020-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
PR (master): https://github.com/appcelerator/titanium_mobile/pull/11859
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
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.v20200814104443and9.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*