Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Inconsistency with appStateChange between iOS and Android #2178

Closed
2 of 4 tasks
Justin-Credible opened this issue Nov 15, 2019 · 1 comment · Fixed by #2179
Closed
2 of 4 tasks

bug: Inconsistency with appStateChange between iOS and Android #2178

Justin-Credible opened this issue Nov 15, 2019 · 1 comment · Fixed by #2179

Comments

@Justin-Credible
Copy link
Contributor

Justin-Credible commented Nov 15, 2019

Bug Report

Capacitor Version

npx cap doctor output:

$ npx cap doctor
💊   Capacitor Doctor  💊 

Latest Dependencies:
  @capacitor/cli: 1.3.0
  @capacitor/core: 1.3.0
  @capacitor/android: 1.3.0
  @capacitor/ios: 1.3.0

Installed Dependencies:
  @capacitor/cli 1.2.1
  @capacitor/core 1.2.1
  @capacitor/ios 1.2.1
  @capacitor/android 1.2.1

Affected Platform(s)

  • Android
  • iOS
  • Electron
  • Web

Current Behavior

The appStateChange event of the App plugin behaves differently between Android and iOS. On Android the retainUntilConsumed flag is true, while on iOS it is false

On Android the retainUntilConsumed is explicitly passed as true: https://github.com/ionic-team/capacitor/blob/master/android/capacitor/src/main/java/com/getcapacitor/plugin/App.java#L27

On iOS the flag is not passed: https://github.com/ionic-team/capacitor/blob/master/ios/Capacitor/Capacitor/Plugins/App.swift#L48-L50

And therefore uses the default of NO as provided by the notifyListeners method seen here: https://github.com/ionic-team/capacitor/blob/master/ios/Capacitor/Capacitor/CAPPlugin.m#L91

This means that if your client JS code adds a listener for appStateChange it will fire on first app boot on Android but not on iOS.

Expected Behavior

Both platforms should behave the same. In our app we've found that we'd rather have the iOS behavior, which ensures the event doesn't fire on first app boot, only when the app resumes from the background.

Reproduction Steps

  1. Create a new Capacitor app
  2. Add a listener for appStateChange via the Capacitor App plugin
  3. Have the handler log an even to the console
  4. Launch the app on Android and iOS

See that the console log statement appears on Android, but not iOS.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 13, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 13, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant