ionic.Platform
A set of utility methods that can be used to retrieve the device ready state and various other information such as what kind of platform the app is currently installed on.
Usage
angular.module('PlatformApp', ['ionic'])
.controller('PlatformCtrl', function($scope) {
ionic.Platform.ready(function(){
// will execute when device is ready, or immediately if the device is already ready.
});
var deviceInformation = ionic.Platform.device();
var isWebView = ionic.Platform.isWebView();
var isIPad = ionic.Platform.isIPad();
var isIOS = ionic.Platform.isIOS();
var isAndroid = ionic.Platform.isAndroid();
var isWindowsPhone = ionic.Platform.isWindowsPhone();
var currentPlatform = ionic.Platform.platform();
var currentPlatformVersion = ionic.Platform.version();
ionic.Platform.exitApp(); // stops the app
});
Methods
ready(callback)
Trigger a callback once the device is ready, or immediately
if the device is already ready. This method can be run from
anywhere and does not need to be wrapped by any additonal methods.
When the app is within a WebView (Cordova), it’ll fire
the callback once the device is ready. If the app is within
a web browser, it’ll fire the callback after window.load.
Please remember that Cordova features (Camera, FileSystem, etc) still
will not work in a web browser.
| Param | Type | Details |
|---|---|---|
| callback |
function
|
The function to call. |
setGrade(grade)
Set the grade of the device: ‘a’, ‘b’, or ‘c’. ‘a’ is the best (most css features enabled), ‘c’ is the worst. By default, sets the grade depending on the current device.
| Param | Type | Details |
|---|---|---|
| grade |
string
|
The new grade to set. |
device()
Return the current device (given by cordova).
- Returns:
objectThe device object.
isWebView()
- Returns:
booleanCheck if we are running within a WebView (such as Cordova).
isIPad()
- Returns:
booleanWhether we are running on iPad.
isIOS()
- Returns:
booleanWhether we are running on iOS.
isAndroid()
- Returns:
booleanWhether we are running on Android.
isWindowsPhone()
- Returns:
booleanWhether we are running on Windows Phone.
isEdge()
- Returns:
booleanWhether we are running on MS Edge/Windows 10 (inc. Phone)
platform()
- Returns:
stringThe name of the current platform.
version()
- Returns:
numberThe version of the current device platform.
is(Platform)
| Param | Type | Details |
|---|---|---|
| Platform |
string
|
name. |
- Returns:
booleanWhether the platform name provided is detected.
exitApp()
Exit the app.
showStatusBar(shouldShow)
Shows or hides the device status bar (in Cordova). Requires cordova plugin add org.apache.cordova.statusbar
| Param | Type | Details |
|---|---|---|
| shouldShow |
boolean
|
Whether or not to show the status bar. |
fullScreen([showFullScreen], [showStatusBar])
Sets whether the app is fullscreen or not (in Cordova).
| Param | Type | Details |
|---|---|---|
|
showFullScreen
(optional)
|
boolean
|
Whether or not to set the app to fullscreen. Defaults to true. Requires |
|
showStatusBar
(optional)
|
boolean
|
Whether or not to show the device's status bar. Defaults to false. |
Properties
-
booleanisReadyWhether the device is ready.
-
booleanisFullScreenWhether the device is fullscreen.
-
Array(string)platformsAn array of all platforms found.
-
stringgradeWhat grade the current platform is.
-
stringuaWhat User Agent is.