Closed ChristopherBrislin closed 1 year ago
same issue on iOS 16
This happens to me as well. Don't paste code because it happens also with plugin's example.
If I run example on android, it works perfectly. If I run it on ios (on device, ios 16.1.1), I get no errors, but task never executes. I was expecting the task to be triggered instantly as it happens on android.
Hi, I inspected the behavior. I upgraded flutter to latest release and my iPhone runs with iOS 16.2. The BGAppRefresh finishes completely. I can see this in debugger notifications. The elapsed time refers to the sleeping time in flutter part.
The issue at the moment seems the isolated SharedPrefs on iOS .
The values are only updated after restart the app.
Therefore I added extra code in my environment today for test purposes.
But this is a SharedPrefs issue which is not to solve at the moment.
I consider to write the data's to an extra file without storing in SharedPrefs.
Be aware iOS is arbitrary and BGRefresh doesn't start like an Android BGTask. Sometimes on iOS the task is called after few minutes, sometimes after two hours.
Please tell me what you want to do. Perhaps I can add a helpful sample code snippet.
@xunreal75 thx for the kind help. Currently Im using workmanager to run a backup task. Im aware that we dont have scheduledtask on ios but thought that task would have run instantly when app is in foreground.
The need is to have task running for at least 20-30sec even if user moves app to background
Hi
I think your idea is the wrong approach. The interval is too short. iOS doesn't give you the resources for that. In foreground Flutter can do this, but in background I see no solution.
You could use notifications to wake up the app in background. This will happen a lot of battery duscharge.
Hi
I think your idea is the wrong approach. The interval is too short. iOS doesn't give you the resources for that. In foreground Flutter can do this, but in background I see no solution.
You could use notifications to wake up the app in background. This will happen a lot of battery duscharge.
Yea, noticed that. We will do incremental daily backup. Data will be <30MB which can be uploaded in <20sec over wifi. Silent notifications from server are killed by ios in many occasion, we use Once to run a background task 2 times a day from foreground state
Hi there, I have the same issue with iOS. Is there a workaround such as an older stable version to alleviate the problem for now? Would appreciate some kind of input from anybody who has testest a stable version for both iOS and Android.
Hi.
I'm recoding at the moment the OnOffTask and looking for other issues.
Further the SharedPrefs reading in isolated doesn't update - updates are only visible after restart app.
I'll solve that by writing log to local filesystem.
There are some (strange) restrictions in iOS.
At the moment the Task starts as AppRefreshTask - means the task starts at any time when iOS like to start.
I will code OnOffTask to start immediately as background task. Problem is that the task can only run 30seconda before IOS will stop it. Long running tasks are not possible on this way.
AppRefresh task starts randomly more often as BGProcessingtask. Runs maximum 29 seconds.
BGProcessingTask can run longtime Tasks in background but it's a little bit tricky because you can't run limitless.
Facing same issue on Ios, Any updates on this ?
@xunreal75 were you able to finalize your solution, if yes could you share the outcome
Further the SharedPrefs reading in isolated doesn't update - updates are only visible after restart app.
If you mean on the dart side then you can use SharedPreferences.getInstance().reload()
to get fresh data
Many good points in this thread. Work on extending background process duration is planned as part of #295.
Will close this ticket in favor of that one.
Version
Describe the error
Have followed all the directions in the iOS setup and guides but am unable to get the plugin to work correctly. No errors are thrown - the callback dispatcher is just never called. The code works without fault on Android. The test environment is a physical device (iPhone XS running iOS 16.1.2) and is being debugged from XCode. The Info.plist has been configured with the correct task indentifier and backgroundFetch seems to work as expected and triggers the callbackDispatcher, but registering a one off task doesn't.
callbackDispatcher as top level function:
my AppDelegate.swift:
I'm calling registerOneOffTask from a Popupmenuitem:
When calling the onTap function this is the debug output:
I noticed that the callback will fire at a very random time (not associated with any input or background fetch) and the task will be in the queue but missing the input data.
I was expecting behaviour similar to what I am seeing in Android where the callback function is triggered nearly immediately upon registering the task. Am I missunderstanding the functionality of this package or have I missused it?
**[β] Flutter (Channel stable, 3.0.3, on macOS 13.0.1 22A400 darwin-x64, locale en-AU) β’ Flutter version 3.0.3 at /Users/ChrisBrislin/Developer/flutter β’ Upstream repository https://github.com/flutter/flutter.git β’ Framework revision 676cefaaff (6 months ago), 2022-06-22 11:34:49 -0700 β’ Engine revision ffe7b86a1e β’ Dart version 2.17.5 β’ DevTools version 2.12.2
[β] Android toolchain - develop for Android devices (Android SDK version 33.0.0) β’ Android SDK at /Users/ChrisBrislin/Library/Android/sdk β’ Platform android-33, build-tools 33.0.0 β’ Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java β’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165) β’ All Android licenses accepted.
[β] Xcode - develop for iOS and macOS (Xcode 14.1) β’ Xcode at /Applications/Xcode.app/Contents/Developer β’ CocoaPods version 1.11.3
[β] Chrome - develop for the web β’ Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[β] Android Studio (version 2020.3) β’ Android Studio at /Applications/Android Studio.app/Contents β’ Flutter plugin can be installed from: π¨ https://plugins.jetbrains.com/plugin/9212-flutter β’ Dart plugin can be installed from: π¨ https://plugins.jetbrains.com/plugin/6351-dart β’ Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7281165)
[β] IntelliJ IDEA Community Edition (version 2021.3.2) β’ IntelliJ at /Applications/IntelliJ IDEA CE.app β’ Flutter plugin can be installed from: π¨ https://plugins.jetbrains.com/plugin/9212-flutter β’ Dart plugin can be installed from: π¨ https://plugins.jetbrains.com/plugin/6351-dart
[β] VS Code (version 1.74.0) β’ VS Code at /Applications/Visual Studio Code.app/Contents β’ Flutter extension version 3.54.0
[β] Connected device (4 available) β’ Chris iphone (mobile) β’ 00008020-001870340E92002E β’ ios β’ iOS 16.1.2 20B110 β’ iPhone 14 (mobile) β’ 91A06788-785D-40B3-AEA8-77AED473ECCF β’ ios β’ com.apple.CoreSimulator.SimRuntime.iOS-16-1 (simulator) β’ macOS (desktop) β’ macos β’ darwin-x64 β’ macOS 13.0.1 22A400 darwin-x64 β’ Chrome (web) β’ chrome β’ web-javascript β’ Google Chrome 108.0.5359.98
[β] HTTP Host Availability β’ All required HTTP hosts are available
β’ No issues found!**