CodeBlanks Logo Icon CodeBlanks

Platform.Version

Learn version detection with Platform.Version.

Platform.Version

Platform.Version gives the operating system version number. On iOS this is a string (for example '14.0'); on Android it is a number (the API level, for example 33). Sometimes you may want to use a feature available only in certain versions.

On Android you do a numeric comparison for version checking: if (Platform.Version >= 33). On iOS a string comparison is needed; therefore iOS version checking is less common. You import Platform.Version together with Platform.

Using Version

On Android Platform.Version is a number; it represents the API level. For example Android 13 has API level 33. To use a feature from a certain API level onward you write if (Platform.Version >= 33).

On iOS Platform.Version is a string (for example '14.4'). Numeric comparison does not work directly; you can convert it with parseInt(Platform.Version, 10) and then compare. At the beginner level the Android API level check is the most common.

Practice Your turn: Android version check

Import Platform. If Platform.Version >= 33 return <Text>New Android</Text>; otherwise return <Text>Old Android</Text>.

Starter code

App.js
import { Text } from 'react-native';

function Screen() {
  // check Android version
  return <Text>Android</Text>;
}

Sample solution

App.js
import { Platform, Text } from 'react-native';

function Screen() {
  if (Platform.Version >= 33) {
    return <Text>New Android</Text>;
  }
  return <Text>Old Android</Text>;
}

Questions and answers

Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.

1 Match: property and return type

Term Meaning
Platform.OS string
Platform.Version number on Android
Platform.select selected value

2 What does Platform.Version return on Android?

App.js
Platform.Version
  • A string
  • An array
  • A component
  • A number (API level) Correct answer

Explanation: On Android Platform.Version gives the API level as a number.

3 Fill in the blank: version access

Question
if (Platform.____ >= 33) { ... }
Answer
if (Platform.Version >= 33) { ... }

Explanation: You read the version with Platform.Version.

All lessons in Beginner