This version of Astro is only compatible with Xcode 7.3
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:

SplashScreenPlugin.init().then(function(splashScreen) {
        Application.isResuming().then(function(isResuming) {
            // Only show the splash screen on a fresh launch.
            if (!isResuming) {
                splashScreen.show();
            }
        });
});

getStartUri() #

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

Sample usage:

var startUrl = 'http://www.mobify.com';

WebViewPlugin.init().then(function(webView) {
        Application.getStartUri().then(function(uri) {
            // 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.

Application.getOSInformation().then(function(osInfo) {
    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.

Application.getOSInformation().then(function(osInfo) {
    if (osInfo.os === Astro.platforms.ios) {
        Application.setStatusBarDarkText();
    }
});

setStatusBarColor(color) - (Android only) #

Sets the color of the status bar.

Application.getOSInformation().then(function(osInfo) {
    if (osInfo.os === Astro.platforms.android) {
        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(function(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
});

Events

receivedDeepLink → {uri} #

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

Sample usage:

WebViewPlugin.init().then(function(webView) {
    // Navigate if we receive a deep link while the app is running.
    Application.on('receivedDeepLink', function(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', function() {
    webView.back();
});

appActivated #

Fires when the app launches or focused from background

Sample usage:

Application.on('appActivated', function() {
    // do something
});

appDeactivated #

Fires when the app terminates or dismissed into the background

Sample usage:

Application.on('appDeactivated', function() {
    // do something
});