0

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?!

Sascha
  • 69
  • 1
  • 7

1 Answers1

1

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
        ...
      }
    })
  }
}
tho-masn
  • 1,126
  • 1
  • 7
  • 13
  • Thank you so much - i was looking at the wrong place ( Ionic Documentation ) the whole time! – Sascha Sep 06 '21 at 14:25