NativeScript Core

Platform

Information and details about the current device, and screen resolution & density are accessible via the platform module.

Usage

const platformModule = require("tns-core-modules/platform");

function onNavigatingTo(args) {
    console.log(`Running on Android? ${platformModule.isAndroid}`);
    console.log(`Running on iOS? ${platformModule.isIOS}`);

    console.log(`device.model ${platformModule.device.model}`); // For example: "Nexus 5" or "iPhone".
    console.log(`device.deviceType ${platformModule.device.deviceType}`); // "Phone" | "Tablet"
    console.log(`device.os ${platformModule.device.os}`); // For example: "Android" or "iOS".
    console.log(`device.osVersion ${platformModule.device.osVersion}`); // For example: 4.4.4(android), 8.1(ios)
    console.log(`device.sdkVersion ${platformModule.device.sdkVersion}`); //  For example: 19(android), 8.1(ios).
    console.log(`device.language ${platformModule.device.language}`); // For example "en" or "en-US".
    console.log(`device.manufacturer ${platformModule.device.manufacturer}`); // For example: "Apple" or "HTC" or "Samsung".
    console.log(`device.uuid ${platformModule.device.uuid}`); // The unique identification number
    console.log(`device.region ${platformModule.device.region}`); //  For example "US".

    console.log(`screen.mainScreen.heightDIPs ${platformModule.screen.mainScreen.heightDIPs}`); // The absolute height of the screen in density independent pixels.
    console.log(`screen.mainScreen.heightPixels ${platformModule.screen.mainScreen.heightPixels}`); // The absolute height of the screen in pixels.
    console.log(`screen.mainScreen.scale ${platformModule.screen.mainScreen.scale}`); // The logical density of the display.
    console.log(`screen.mainScreen.widthDIPs ${platformModule.screen.mainScreen.widthDIPs}`); // The absolute width of the screen in density independent pixels.
    console.log(`screen.mainScreen.widthPixels ${platformModule.screen.mainScreen.widthPixels}`); // The absolute width of the screen in pixel
}

exports.onNavigatingTo = onNavigatingTo;
import { device, screen, isAndroid, isIOS } from "tns-core-modules/platform";

export function onNavigatingTo(args) {
    console.log(`Running on Android? ${isAndroid}`);
    console.log(`Running on iOS? ${isIOS}`);

    console.log(`device.model ${device.model}`); // For example: "Nexus 5" or "iPhone".
    console.log(`device.deviceType ${device.deviceType}`); // "Phone" | "Tablet"
    console.log(`device.os ${device.os}`); // For example: "Android" or "iOS".
    console.log(`device.osVersion ${device.osVersion}`); // For example: 4.4.4(android), 8.1(ios)
    console.log(`device.sdkVersion ${device.sdkVersion}`); //  For example: 19(android), 8.1(ios).
    console.log(`device.language ${device.language}`); // For example "en" or "en-US".
    console.log(`device.manufacturer ${device.manufacturer}`); // For example: "Apple" or "HTC" or "Samsung".
    console.log(`device.uuid ${device.uuid}`); // The unique identification number
    console.log(`device.region ${device.region}`); //  For example "US".

    console.log(`screen.mainScreen.heightDIPs ${screen.mainScreen.heightDIPs}`); // The absolute height of the screen in density independent pixels.
    console.log(`screen.mainScreen.heightPixels ${screen.mainScreen.heightPixels}`); // The absolute height of the screen in pixels.
    console.log(`screen.mainScreen.scale ${screen.mainScreen.scale}`); // The logical density of the display.
    console.log(`screen.mainScreen.widthDIPs ${screen.mainScreen.widthDIPs}`); // The absolute width of the screen in density independent pixels.
    console.log(`screen.mainScreen.widthPixels ${screen.mainScreen.widthPixels}`); // The absolute width of the screen in pixel
}

Improve this document

Demo Source


Properties

Name Type Description
device Device Gets the current device information.
isAndroid boolean Gets a value indicating if the app is running on the Android platform.
isIOS boolean Gets a value indicating if the app is running on the iOS platform.
screen Screen Module For details see the Screen module properties.

Screen Module Properties

Name Type Description
mainScreen ScreenMetrics Gets information about the main screen of the current device.

API References

Name Type
tns-core-modules/platform Module
Device Interface
ScreenMetrics Interface