nativescript-platform-free
v1.3.2
Published
A NativeScript plugin to easily deal with getting the platform running on. Since the original plugin requires a subscription now, this plugin is my attempt to maintain it to the point where it does not break.
Downloads
5
Maintainers
Readme
nativescript-platform-free
A NativeScript plugin to easily deal with and detect which platform you are on. Since the original plugin requires a subscription now, this plugin is my attempt to maintain it to the point where it does not break.
Developed by
License
This is released under the MIT License, meaning you are free to include this in any type of program -- However for entities that need a support contract, changes, enhancements and/or a commercial license please contact me at http://nativescript.tools.
I also do contract work; so if you have a module you want built for NativeScript (or any other software projects) feel free to contact me [email protected].
Requirements
Any version of NativeScript
Installation
tns plugin add nativescript-platform
Usage
To use the module you just require()
it:
var myPlatform = require( "nativescript-platform" );
if (myPlatform.android) {
// do android specific stuff
}
please note you can also simple do, and then the nsPlatform will be available globally everywhere:
require( "nativescript-platform" );
if (nsPlatform.ios) {
// do ios specific stuff
}
nsPlatform will be declared globally. My recommendation is just to include it in the app.js and then use it everywhere.
You ask, how exactly does this help?
This wraps up several simple ways to check for the platform you are on. This comes up commonly when you are trying to do stuff on just one platform.
Breaking changes
Removed initial windows phone support, its been 4 years -- I don't think NativeScript will ever build actual windows phone apps.
API
Functions
- .isAndroid();
- .isIOS(); returns true or false depending on the platform it is on Example:
if (nsPlatform.isAndroid()) { /* do my android specific stuff */ }
- .hasSoftNav(); returns if device is using Soft Navigation.
Variables
- .ios
- .android
- Is set to either true or false for the platform it is on Example:
if (nsPlatform.ios) { /* do my ios specific stuff */ }
Switch Statement support
.platform
- .type.IOS
- .type.ANDROID Example:
switch (nsPlatform.platform) {
case nsPlatform.type.IOS: // Do iOS stuff
case nsPlatform.type.ANDROID: // Do Android stuff
}
.deviceType
Tablet
or Phone
.screen
- .width - Width of Screen (DIP)
- .height - Height of Screen (DIP)
- .scale - Scale of Screen (DIP)
- .widthPixels - Width of Screen (Pixels)
- .heightPixels - Height of Screen (Pixels)
.device
- .emulator - True or False
- .model - Model number of device
- .name - Name of device (might be the same as model)
- .manufacturer - Manufacturer of the device
- .notch - true or false, if device has a notch.
- .buttonLess - true or false, APPLE only -- if the device has no home button. ( .hasSoftNav() supports both android and ios )
console.log(nsPlatform.manufacturer, nsPlatform.name);
// Outputs: "Apple iPhoneX"