Skip to content

bug: App.addListener indicates app is running in the background after modal pops up #4597

@ignacio-ambia-bego

Description

@ignacio-ambia-bego

Bug Report

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 3.0.0
  @capacitor/core: 3.0.0
  @capacitor/android: 3.0.0
  @capacitor/electron: 3.0.0
  @capacitor/ios: 3.0.0

Installed Dependencies:

  @capacitor/cli 2.4.0
  @capacitor/android 2.4.5
  @capacitor/core 2.4.0
  @capacitor/ios 2.4.0
  @capacitor/electron not installed

[success] Android looking great! 👌
  Found 14 Capacitor plugins for ios:
    @rdlabo/capacitor-facebook-login (2.0.3)
    com-sarriaroman-photoviewer (1.2.5)
    cordova-background-geolocation-lt (4.0.1)
    cordova-plugin-actionsheet (2.3.3)
    cordova-plugin-background-fetch (7.0.1)
    cordova-plugin-contacts (3.0.1)
    cordova-plugin-dialogs (2.0.2)
    cordova-plugin-geolocation (4.0.2)
    cordova-plugin-smartlook (1.7.4)
    cordova-plugin-streaming-media (2.3.0)
    cordova-plugin-x-socialsharing (6.0.3)
    cordova.plugins.diagnostic (6.0.3)
    es6-promise-plugin (4.2.2)
    uk.co.workingedge.phonegap.plugin.launchnavigator (5.0.5)
[success] iOS looking great! 👌

Platform(s)

It is only affecting IOS, at least versions 14.5 & 12

Current Behavior

I added the listener App.addListener to my project to detect when app just came back from background and do something.
When the listener is triggered, it shows an alert if the location permission is disabled in the device. The things is that when another alert show up, such as the one to access the camera, the listener triggers again, just as if the app was moved to the background.

Expected Behavior

When native alerts show up, it shouldn't be considered as if the app went to the background.
Is there a way to avoid this from happening?

Code Reproduction

    App.addListener('appStateChange', (state: AppState) => {
      if(state.isActive) {
        console.log('App has become active');

       //if this line is commented the error disappears, this line is the one that causes the alert to show up, 
       //thus triggering the listener once again 
        this.startWatchPosition();
      } else {
        console.log('App has become inactive');
        BackgroundGeolocation.stopWatchPosition();
      }
    });


  startWatchPosition() {
    BackgroundGeolocation.watchPosition((location) => {
      console.log("[watchPosition] -", location);
      this.broadcastCoordsService.emit({
        "coords": location
      });

Other Technical Details

npm --version output: 7.11.2

node --version output: v14.16.0

pod --version output (iOS issues only):
WARNING: CocoaPods requires your terminal to be using UTF-8 encoding.
Consider adding the following to ~/.profile:

export LANG=en_US.UTF-8

Ignoring ffi-1.13.1 because its extensions are not built. Try: gem pristine ffi --version 1.13.1
1.10.1

Additional Context

By native alerts i mean the ones that show up when permissions for camera, location, contacts, etc.. are asked by OS

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions