AppStateIOS
AppStateIOS
can tell you if the app is in the foreground or background,
and notify you when the state changes.
AppStateIOS is frequently used to determine the intent and proper behavior when handling push notifications.
iOS App States #
active
- The app is running in the foregroundbackground
- The app is running in the background. The user is either in another app or on the home screeninactive
- This is a transition state that currently never happens for typical React Native apps.
For more information, see Apple's documentation
Basic Usage #
To see the current state, you can check AppStateIOS.currentState
, which
will be kept up-to-date. However, currentState
will be null at launch
while AppStateIOS
retrieves it over the bridge.
This example will only ever appear to say "Current state is: active" because
the app is only visible to the user when in the active
state, and the null
state will happen only momentarily.
Methods #
Properties #
currentState: TypeCastExpression #
// TODO: getCurrentAppState callback seems to be called at a really late stage // after app launch. Trying to get currentState when mounting App component // will likely to have the initial value here. // Initialize to 'active' instead of null.