Sascha
Sascha

Reputation: 79

Run action before Ionic Vue closes or app runs in background

How can i detect in Ionic Vue if the app closes or if the app is send to the background?

this.platformor platform isn't available or does not work?!

Upvotes: 0

Views: 498

Answers (1)

tho-masn
tho-masn

Reputation: 1174

You can subscribe to the appStateChange event, like described here: https://capacitorjs.com/docs/apis/app

Example:

import { App } from '@capacitor/app'

export default {
  created () {
    App.addListener('appStateChange', state => {
      if (!state.isActive) { // if isActive is true, App got sent to foreground, if it is false, it got sent to the background
        ...
      }
    })
  }
}

Upvotes: 1

Related Questions