aws-amplify / amplify-flutter

A declarative library with an easy-to-use interface for building Flutter applications on AWS.
https://docs.amplify.aws
Apache License 2.0
1.31k stars 243 forks source link

iOS sync stop when app is in background and screen off only in Release #5041

Open JeremyLabelIO opened 3 months ago

JeremyLabelIO commented 3 months ago

Description

Hi,

After updating amplify_flutter and amplify_datastore from 1.8.0 to 2.1.0 if I put my iOS app in background, turn off the screen, the sync is completely stopped. The only way to start sync again is to kill the app and relaunch it.

Everything works fine in debug but not in release.

I already try this :

As of next steps, please enable optimizations in your debug build and see if the issue is occurring when enabling the optimization. In addition, by using this way you will be able to obtain logs regarding the issue: https://github.com/apple/swift/blob/main/docs/OptimizationTips.rst#enabling-optimizations

But I have still no logs and no changes.

flutter doctor Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 3.22.2, on macOS 14.1 23B74 darwin-arm64, locale fr-FR) [✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 15.4) [✓] Chrome - develop for the web [✓] Android Studio (version 2023.3)

Pubspec :

environment: sdk: '>=3.3.0 <4.0.0'

dependencies: flutter: sdk: flutter flutter_localizations: sdk: flutter flutter_launcher_icons: intl: ^0.19.0 amplify_flutter: 2.1.0 amplify_datastore: 2.1.0 amplify_api: 2.1.0 amplify_auth_cognito: 2.1.0 amplify_storage_s3: 2.1.0

Categories

Steps to Reproduce

  1. Start the app on your iPhone and check sync work normally.
  2. Put the app in background
  3. Turn off the screen
  4. Do some changes in another device
  5. Reopen the app on your iPhone
  6. You do not receive any update from the cloud
  7. If you want to have update again, you have to kill the app and relaunch it.

Screenshots

No response

Platforms

Flutter Version

3.22.2

Amplify Flutter Version

2.1.0

Deployment Method

Amplify CLI

Schema

No response

tyllark commented 3 months ago

Hello @JeremyLabelIO thank you for submitting this issue. We will look into this and get back to you!

Equartey commented 3 months ago

Hi @JeremyLabelIO,

Are you pausing the app during a sync? Or do you lose sync functionality when pausing the app?

DataStore changed in 2.1.0 to use our Dart first API category instead of using Amplify Swift under the hood. I suspect subscriptions management differs, specifically when the app isn't in the foreground.

In the meantime, give one of these two workarounds a try.

  1. Manage sync yourself during the App's lifecycle. For example, call start/stop DataStore when the app is being pause/resumed.
  2. Amplify Flutter 2.0.0 uses Amplify Swift and may unblock you in the interim.

These are just my initial thoughts. We'll provide a more concrete solution once we've looked into it more.

JeremyLabelIO commented 3 months ago

Hi @Equartey

I already try to stop and start DataStore when the app is being pause/resumed but without success.

I confirm it is working with Amplify Flutter 2.0.0 but I have other issue with this version (mostly in Android) and it is complicated for us to maintain different version for iOS and Android.

Do you think it will be fix soon ?

Best Regards,

Jeremy

tyllark commented 3 months ago

Hi @JeremyLabelIO

I was able to reproduce the syncing issue following the steps you provided. We will track this as a bug and will let you know if there are any updates.

JeremyLabelIO commented 3 months ago

Hi @tyllark

Thanks a lot.

tyllark commented 3 months ago

No problem, we will let you know when we have an update.

gauravwagh1 commented 4 days ago

Hello @tyllark

We are encountering the same issue with API (GraphQL) subscriptions, where the sync stops when the app is in the background or the screen is off (only in Release mode). Could you please provide any updates on when this issue might be resolved?

Thank you!

khatruong2009 commented 2 days ago

Hi @gauravwagh1, we are still working to determine the root cause and will get back to you with any updates.