
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@capacitor/app
Advanced tools
The App API handles high level App state and events.For example, this API emits events when the app enters and leaves the foreground, handles deeplinks, opens other apps, and manages persisted plugin state.
@capacitor/app is a Capacitor plugin that provides various functionalities related to the app lifecycle and state. It allows developers to handle app state changes, manage app URLs, and more.
App State
This feature allows you to listen for changes in the app's state, such as when the app becomes active or goes into the background.
import { App } from '@capacitor/app';
App.addListener('appStateChange', (state) => {
console.log('App state changed. Is active:', state.isActive);
});
App URL Open
This feature allows you to handle URLs that open your app, which is useful for deep linking.
import { App } from '@capacitor/app';
App.addListener('appUrlOpen', (data) => {
console.log('App opened with URL:', data.url);
});
App Restored Result
This feature allows you to handle the result when your app is restored from a terminated state.
import { App } from '@capacitor/app';
App.addListener('appRestoredResult', (data) => {
console.log('App restored with result:', data);
});
Get Launch URL
This feature allows you to get the URL that was used to launch the app.
import { App } from '@capacitor/app';
App.getLaunchUrl().then((data) => {
console.log('App launched with URL:', data.url);
});
Minimize App
This feature allows you to programmatically minimize the app.
import { App } from '@capacitor/app';
App.minimizeApp();
cordova-plugin-app-event is a Cordova plugin that provides event listeners for app lifecycle events. It offers similar functionalities for handling app state changes and URL events. However, it is specific to Cordova and may not be as integrated with modern frameworks like Capacitor.
expo-app-loading is an Expo package that helps manage the app loading state. While it does not provide the full range of functionalities of @capacitor/app, it is useful for managing the app's loading state and ensuring that the app is fully loaded before rendering. It is specific to Expo and React Native.
The App API handles high level App state and events.For example, this API emits events when the app enters and leaves the foreground, handles deeplinks, opens other apps, and manages persisted plugin state.
npm install @capacitor/app
npx cap sync
exitApp()
getInfo()
getState()
getLaunchUrl()
addListener(...)
addListener(...)
addListener(...)
addListener(...)
removeAllListeners()
exitApp() => never
Force exit the app. This should only be used in conjunction with the backButton
handler for Android to
exit the app when navigation is complete.
Ionic handles this itself so you shouldn't need to call this if using Ionic.
Returns: never
Since: 1.0.0
getInfo() => Promise<AppInfo>
Return information about the app.
Returns: Promise<AppInfo>
Since: 1.0.0
getState() => Promise<AppState>
Gets the current app state.
Returns: Promise<AppState>
Since: 1.0.0
getLaunchUrl() => Promise<AppLaunchUrl>
Get the URL the app was launched with, if any.
Returns: Promise<AppLaunchUrl>
Since: 1.0.0
addListener(eventName: 'appStateChange', listenerFunc: (state: AppState) => void) => PluginListenerHandle
Listen for changes in the App's active state (whether the app is in the foreground or background)
Param | Type |
---|---|
eventName | "appStateChange" |
listenerFunc | (state: AppState) => void |
Returns: PluginListenerHandle
Since: 1.0.0
addListener(eventName: 'appUrlOpen', listenerFunc: (data: AppUrlOpen) => void) => PluginListenerHandle
Listen for url open events for the app. This handles both custom URL scheme links as well as URLs your app handles (Universal Links on iOS and App Links on Android)
Param | Type |
---|---|
eventName | "appUrlOpen" |
listenerFunc | (data: AppUrlOpen) => void |
Returns: PluginListenerHandle
Since: 1.0.0
addListener(eventName: 'appRestoredResult', listenerFunc: (data: AppRestoredResult) => void) => PluginListenerHandle
If the app was launched with previously persisted plugin call data, such as on Android when an activity returns to an app that was closed, this call will return any data the app was launched with, converted into the form of a result from a plugin call.
Param | Type |
---|---|
eventName | "appRestoredResult" |
listenerFunc | (data: AppRestoredResult) => void |
Returns: PluginListenerHandle
Since: 1.0.0
addListener(eventName: 'backButton', listenerFunc: () => void) => PluginListenerHandle
Listen for the hardware back button event (Android only). Listening for this event will disable the
default back button behaviour, so you might want to call window.history.back()
manually.
If you want to close the app, call App.exitApp()
.
Param | Type |
---|---|
eventName | "backButton" |
listenerFunc | () => void |
Returns: PluginListenerHandle
Since: 1.0.0
removeAllListeners() => void
Remove all native listeners for this plugin
Since: 1.0.0
Prop | Type | Description | Since |
---|---|---|---|
name | string | The name of the app. | 1.0.0 |
id | string | The identifier of the app. On iOS it's the Bundle Identifier. On Android it's the Application ID | 1.0.0 |
build | string | The build version. On iOS it's the CFBundleVersion. On Android it's the versionCode. | 1.0.0 |
version | string | The app version. On iOS it's the CFBundleShortVersionString. On Android it's package's versionName. | 1.0.0 |
Prop | Type | Description | Since |
---|---|---|---|
isActive | boolean | Whether the app is active or not. | 1.0.0 |
Prop | Type | Description | Since |
---|---|---|---|
url | string | The url used to open the app. | 1.0.0 |
Prop | Type |
---|---|
remove | () => void |
Prop | Type | Description | Since |
---|---|---|---|
url | string | The URL the app was opened with. | 1.0.0 |
iosSourceApplication | any | The source application opening the app (iOS only) https://developer.apple.com/documentation/uikit/uiapplicationopenurloptionskey/1623128-sourceapplication | 1.0.0 |
iosOpenInPlace | boolean | Whether the app should open the passed document in-place or must copy it first. https://developer.apple.com/documentation/uikit/uiapplicationopenurloptionskey/1623123-openinplace | 1.0.0 |
Prop | Type | Description | Since |
---|---|---|---|
pluginId | string | The pluginId this result corresponds to. For example, Camera . | 1.0.0 |
methodName | string | The methodName this result corresponds to. For example, getPhoto | 1.0.0 |
data | any | The result data passed from the plugin. This would be the result you'd expect from normally calling the plugin method. For example, CameraPhoto | 1.0.0 |
success | boolean | Boolean indicating if the plugin call succeeded. | 1.0.0 |
error | { message: string; } | If the plugin call didn't succeed, it will contain the error message. | 1.0.0 |
FAQs
The App API handles high level App state and events.For example, this API emits events when the app enters and leaves the foreground, handles deeplinks, opens other apps, and manages persisted plugin state.
The npm package @capacitor/app receives a total of 167,683 weekly downloads. As such, @capacitor/app popularity was classified as popular.
We found that @capacitor/app demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 8 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.