$ionicPlatform

An angular abstraction of ionic.Platform.

Used to detect the current platform, as well as do things like override the Android back button in PhoneGap/Cordova.

Methods

onHardwareBackButton(callback)

Some platforms have a hardware back button, so this is one way to bind to it.

Param Type Details
callback function

the callback to trigger when this event occurs

offHardwareBackButton(callback)

Remove an event listener for the backbutton.

Param Type Details
callback function

The listener function that was originally bound.

registerBackButtonAction(callback, priority, [actionId])

Register a hardware back button action. Only one action will execute when the back button is clicked, so this method decides which of the registered back button actions has the highest priority.

For example, if an actionsheet is showing, the back button should close the actionsheet, but it should not also go back a page view or close a modal which may be open.

The priorities for the existing back button hooks are as follows: Return to previous view = 100 Close side menu = 150 Dismiss modal = 200 Close action sheet = 300 Dismiss popup = 400 Dismiss loading overlay = 500

Your back button action will override each of the above actions whose priority is less than the priority you provide. For example, an action assigned a priority of 101 will override the ‘return to previous view’ action, but not any of the other actions.

Param Type Details
callback function

Called when the back button is pressed, if this listener is the highest priority.

priority number

Only the highest priority will execute.

actionId
(optional)
*

The id to assign this action. Default: a random unique id.

  • Returns: function A function that, when called, will deregister this backButtonAction.

on(type, callback)

Add Cordova event listeners, such as pause, resume, volumedownbutton, batterylow, offline, etc. More information about available event types can be found in Cordova’s event documentation.

Param Type Details
type string

Cordova event type.

callback function

Called when the Cordova event is fired.

  • Returns: function Returns a deregistration function to remove the event listener.

ready([callback])

Trigger a callback once the device is ready, or immediately if the device is already ready.

Param Type Details
callback
(optional)
function=

The function to call.

  • Returns: promise A promise which is resolved when the device is ready.