amplify-flutter icon indicating copy to clipboard operation
amplify-flutter copied to clipboard

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

Open JeremyLabelIO opened this issue 1 year ago • 14 comments

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

  • "In the Project Navigator, select the project icon to enter the Project Editor. In the project editor, select the icon under the "Project" header to enter the project settings editor. From there, an optimization setting can be applied to every target in the project by changing the "Optimization Level" field under the "Build Settings" header."

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

  • [ ] Analytics
  • [ ] API (REST)
  • [ ] API (GraphQL)
  • [ ] Auth
  • [ ] Authenticator
  • [X] DataStore
  • [ ] Notifications (Push)
  • [ ] Storage

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

  • [X] iOS
  • [ ] Android
  • [ ] Web
  • [ ] macOS
  • [ ] Windows
  • [ ] Linux

Flutter Version

3.22.2

Amplify Flutter Version

2.1.0

Deployment Method

Amplify CLI

Schema

No response

JeremyLabelIO avatar Jun 20 '24 09:06 JeremyLabelIO

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

tyllark avatar Jun 20 '24 17:06 tyllark

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.

Equartey avatar Jun 20 '24 17:06 Equartey

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

JeremyLabelIO avatar Jun 21 '24 07:06 JeremyLabelIO

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.

tyllark avatar Jun 21 '24 21:06 tyllark

Hi @tyllark

Thanks a lot.

JeremyLabelIO avatar Jun 22 '24 10:06 JeremyLabelIO

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

tyllark avatar Jun 25 '24 15:06 tyllark

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!

gauravwagh1 avatar Sep 24 '24 05:09 gauravwagh1

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

khatruong2009 avatar Sep 26 '24 05:09 khatruong2009

Hi @JeremyLabelIO,

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

A bug was fixed in Amplify DataStore 2.4.1 that resolved this workaround. Can you give it another try on this version?

Equartey avatar Oct 01 '24 16:10 Equartey

I'm going to close this issue as we've released a fix for it. If you have additional questions, please open a new issue.

NikaHsn avatar Oct 16 '24 17:10 NikaHsn

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Oct 16 '24 17:10 github-actions[bot]

Hello @JeremyLabelIO and @gauravwagh1 sorry for the delay but we now have a fix for this issue under review. We will provide updates here when the fix is release, but in the meantime you can override your dependencies with the fix by including the following in your pubspec.yaml.

dependency_overrides:
  amplify_api:
    git:
      url: https://github.com/aws-amplify/amplify-flutter
      ref: fix/app-life-cycle-datastore-websockets
      path: packages/api/amplify_api
  
  amplify_api_dart:
    git:
      url: https://github.com/aws-amplify/amplify-flutter
      ref: fix/app-life-cycle-datastore-websockets
      path: packages/api/amplify_api_dart

Please let us know if you have any issues with this workaround.

tyllark avatar Oct 17 '24 23:10 tyllark

Hello @JeremyLabelIO and @gauravwagh1 sorry for the delay but we now have a fix for this issue under review. We will provide updates here when the fix is release, but in the meantime you can override your dependencies with the fix by including the following in your pubspec.yaml.

dependency_overrides:
  amplify_api:
    git:
      url: https://github.com/aws-amplify/amplify-flutter
      ref: fix/app-life-cycle-datastore-websockets
      path: packages/api/amplify_api
  
  amplify_api_dart:
    git:
      url: https://github.com/aws-amplify/amplify-flutter
      ref: fix/app-life-cycle-datastore-websockets
      path: packages/api/amplify_api_dart

Please let us know if you have any issues with this workaround.

@tyllark Thank you so much for the workaround. I’ve tested it by overriding the dependencies as suggested, and it’s working well on our end. Do you have an estimated timeline for the official release of this fix? It would be helpful to know if there’s an ETA available.

gauravwagh1 avatar Oct 18 '24 07:10 gauravwagh1

Hi @gauravwagh1 I just merged the changes. I will aim to schedule a release early next week. We will post here when the release is live.

tyllark avatar Oct 18 '24 22:10 tyllark

Hello @JeremyLabelIO and @gauravwagh1 the fix has been released! Please update your packages to 2.4.2.

tyllark avatar Oct 22 '24 22:10 tyllark

This issue is now closed. Comments on closed issues are hard for our team to see. If you need more assistance, please open a new issue that references this one.

github-actions[bot] avatar Oct 22 '24 22:10 github-actions[bot]