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:
object
The device object.
isWebView()
- Returns:
boolean
Check if we are running within a WebView (such as Cordova).
isIPad()
- Returns:
boolean
Whether we are running on iPad.
isIOS()
- Returns:
boolean
Whether we are running on iOS.
isAndroid()
- Returns:
boolean
Whether we are running on Android.
isWindowsPhone()
- Returns:
boolean
Whether we are running on Windows Phone.
isEdge()
- Returns:
boolean
Whether we are running on MS Edge/Windows 10 (inc. Phone)
platform()
- Returns:
string
The name of the current platform.
version()
- Returns:
number
The version of the current device platform.
is(Platform)
Param | Type | Details |
---|---|---|
Platform |
string
|
name. |
- Returns:
boolean
Whether 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
-
boolean
isReady
Whether the device is ready.
-
boolean
isFullScreen
Whether the device is fullscreen.
-
Array(string)
platforms
An array of all platforms found.
-
string
grade
What grade the current platform is.