Menu

Application

The Application class handles configuration related to the app such as setting its root view and dispatching an event when a deep link is received.

Methods

isResuming() #

Returns true if the app is resuming, i.e. it is launched with a savedInstanceState bundle.

Sample usage:

const webView = await WebViewPlugin.init()
const welcomeModal = await ModalViewPlugin.init()

webView.navigate('file:///welcome.html')
welcomeModal.setContentView(webView)
const isResuming = await Application.isResuming()
// Only show the welcome modal on a fresh launch.
if (!isResuming) {
    welcomeModal.show()
}

getStartUri() #

If the app was started via a deep link, this returns the uri, otherwise it returns null.

Sample usage:

const startUrl = 'http://www.mobify.com'

const webView = await WebViewPlugin.init()
const uri = await Application.getStartUri()

// Override the start url if the app was started via a deep link.
if (uri) {
    startUrl = uri;
}
webView.navigate(startUrl);

setMainViewPlugin(plugin) #

Sets a plugin's view as the app's primary view.

Note: This method can safely be called more than once to swap in a different main view plugin. Subsequent calls simply remove the previous main view plugin from the view hierarchy but do not clean up the plugin (ie. the old plugin can be put back in when needed).

This call must be completed before any UI transitions on the eventual main view plugin and/or its children.


getOSInformation() #

Retrieves information about the devices OS such as the operating system, and it's version in a JSON dictionary.

Example:

{
  "os": "Android",
  "version": "5.0.1"
}

Platforms are defined in Astro.platforms. You can compare the os value to Astro.platforms.android or Astro.platforms.ios to detect the current platform.


getAppInformation() #

Retrieves information about the app, such as a unique identifier for the device.

Example:

{
  "installationID": "43a7cb19e48d5f"
}

openStore() #

Opens the Apple app store or Google play store to your app's page.


openInBrowser(url) #

Opens a url in an external browser. On Android, it will list the apps that can handle the given url. On iOS it will open the url in Safari.


openLocationSettings #

Opens the Settings application navigated to the page that lets the user either:


setStatusBarLightText() - (iOS only) #

Sets the text color of the status bar on iOS to a white color.

const osInfo = await Application.getOSInformation()
if (osInfo.os === Astro.platforms.ios) {
    Application.setStatusBarLightText()
}

setStatusBarDarkText() - (iOS only) #

Sets the text color of the status bar on iOS to a dark color.

const osInfo = await Application.getOSInformation()
if (osInfo.os === Astro.platforms.ios) {
    Application.setStatusBarDarkText()
}

setStatusBarColor(color) - (Android only) #

Sets the color of the status bar.

const osInfo = await Application.getOSInformation()
Application.setStatusBarColor('#00AA22')

setBackgroundColor(color) #

Sets the background color of the root view.

Sample usage:

Application.setBackgroundColor('#000000') // Black

closeApp() #

Closes the app (Android only)

Sample usage:

Application.closeApp()

addDeepLinkHandler(handler) #

Adds a deeplink handler function to a list of handlers. When private:receivedDeepLink is called, these handlers can optionally short-circuit the deep link process and perform custom logic. Currently used by the PushPlugin. The handlers are evaluated in the order they were added. If no handlers handle the event, then receivedDeepLink will be called.

Sets a plugin's view as the app's primary view.

Sample usage:

Application.addDeepLinkHandler((params) => {
    if (params.uri === uriYouWantToMatch) {
        // Perform custom logic
        return true // we don't want the normal deeplink logic to perform
    }
    return false // Didn't match
})

dismissLaunchImage #

Dismisses the Astro App Launch image. Call this to dismiss the custom launch image in Android created by including the launch_view layout in your project.

Sample usage:

Application.dismissLaunchImage()

Events

receivedDeepLink → {uri} #

Fires when the app receives a deep link while it is already running.

Sample usage:

const webView = await WebViewPlugin.init()
// Navigate if we receive a deep link while the app is running.
Application.on('receivedDeepLink', (params) => {
    webView.navigate(params.uri)
})
webView.navigate('http://www.mobify.com')

backButtonPressed #

Fires when the app receives a back button press (Android only)

Sample usage:

Application.on('backButtonPressed', () => {
    webView.back()
})

appActivated #

Fires when the app launches or focused from background

Sample usage:

Application.on('appActivated', () => {
    // do something
})

appDeactivated #

Fires when the app terminates or dismissed into the background

Sample usage:

Application.on('appDeactivated', () => {
    // do something
})