I tried to use the iOS 13 background tasks, with the Apple Example:
https://developer.apple.com/documentation/backgroundtasks/refreshing_and_maintaining_your_app_using_background_tasks
But the application works perfectly fine if i use in debug mode(Using the below apple commands provided)
https://developer.apple.com/documentation/backgroundtasks/starting_and_terminating_tasks_during_development
On a release mode(with out console commands) not even once triggered the background tasks, i tried
Connecting the application to Xcode with breakpoints.
Giving a local notification when background tasks trigger.
Using Userdefaults to keep count of number of Event Triggers.
None of them gave me an answer, Tried for whole day.
So wanted to understand, if any one has used iOS 13 background tasks, could please help me guide what im missing.
Thanks.
Related
I'm building a Flutter app and need to call a function every day (to schedule some notifications). I came across the flutter_background_fetch package, which seems to be a perfect solution for Android, since the main limitation of the minimum 15 minute interval is not a problem.
However, I am supremely confused about how well the package works for iOS. According to the README, "When your app is terminated, iOS no longer fires events". However, I've also seen posts on Stackoverflow that claim that iOS Background App Refresh periodically relaunches your app to run background fetches (and posts that say it is unreliable or doesn't work at all).
So does flutter_background_fetch work on iOS when the app is terminated (eg. double tap home and swipe up)?
Edit: Also exploring flutter_workmanager, which seems promising.
There is no perfect Dart solution for iOS to schedule background task as android when app terminate, in android we can use Alarm Manager
But you can try native side implementation with BGTaskScheduler
https://github.com/fluttercommunity/flutter_workmanager
My iOS app gets terminated when put in background. I get the following logs in the device console:
Background Task 160 (""), was created over 30 seconds ago. In applications running in the background, this creates a risk of termination. Remember to call UIApplication.endBackgroundTask(_:) for your task in a timely manner to avoid this.
followed by
Background task still not ended after expiration handlers were called: . This app will likely be terminated by the system. Call UIApplication.endBackgroundTask(_:) to avoid this.
and the app terminates and restarts on resuming from background
The new metric kit background exit data (iOS 14) is also reporting that BackgroundTaskAssertionTimeoutExits are killing my app
On breaking on UIApplicationEndBackgroundTaskError, I get the following backtrace:
I have not implemented any background tasks myself but there are some third party libraries integrated in the app that do.
What is the right way to debug this?
If you did not start any background task, and you do not perform anything most likely some of your 3rd party frameworks are causing the crash.
Update to latest version of all your dependencies, to see if the issue was fixed.
If your issue is easily reproducible, try to disable them 1 by 1 to see which is causing the crash.
After that go on the library support page and see if there are any bugs for your issue and if not open a bug.
Start with the usual suspects, Analytics, Loggers and go on.
Have a look also at this thread: App is crashing on only iOS 13 in the background mode
i'm trying to get the new BackgroundTask framework to work in my app. I'm testing on a real device running iOS 13.4.
Everything works as expected (minimal setup, like is described here: https://developer.apple.com/documentation/backgroundtasks/bgtaskscheduler )
Unfortunately the task gets only called if the app is still in the background. If applicationWillTerminate() is called (e.g. when the user closes the app from the multitasking manager), the task will not get executed.
I have not found anything on this topic in the docs. Also i think this behaviour was different with the now deprecated Background Modes (see also: iOS - Background Services when app is terminated )
Can anyone clarify/confirm/correct on this?
Thanks in advance!
I would like to run two applications from two XCode GUI instances on iPhone Simulator,
The two apps communicate with each other using socket and I would like to do step by step debugging in each app to debug the some logic internally.
I wish to use the debugger and do step by step in each XCode instance while the two apps are running on the iPhone simulator
The issue is that I can only use breakpoint\stop the run in one XCode instance while the other XCode\app seems to be running (the title in the target is "Running ..") but could not catch the breakpoint or even see any print\traces in the XCode debug console.
Any idea what could be the issue?
Thank you!
Ronen
I just tried debugging two apps simultaneously on the iOS simulator, and simple things seem to work correctly.
Remember that on iOS, apps that are not in the foreground are generally suspended unless they register background tasks. So only the foreground one is going to make any progress. But that's true regardless of whether you are in the debugger or not.
If one or the other apps has registered a background task, and that background task isn't getting any time when you have this scenario of two apps running under the debugger, please file a bug with an example of your scenario at http://bugreporter.apple.com.
But if you want to follow foreground processing in the two apps, you'll have to manually foreground the one you want to run as you are stepping along. But that's just a reflection of how apps run on iOS.
application:handleEventsForBackgroundURLSession:completionHandler: doesn't run when the uploads are finished in the background. When all the upload/download tasks are completed in the background then iOS should wake up the app and call the above method. But it doesn't.
I have tested this by terminating the app from 'xcode stop' button and also terminated from an exception.
I have followed Background Transfer consideration.
I have tested this on Apple developer guide: Background example and it is not working.
I have also tested this on AppCoda: Background example and it is not working
Both of the examples which are given in 2 and 3 points are not working on iOS 9.0 and xCode 7.0. Before upgrading to iOS9.0, I had tested this on iOS7.0 and xcode 5.0 where it ran perfectly.
I am assuming that it would work on the real device.
What am I missing here? Can anybody confirm whether handleEventsForBackgroundURLSession works in iOS9.0 simulator or am I doing anything wrong? Since it doesn't work for the examples given in 2 and 3 so I guess maybe I am testing it wrong.
#ZayinKrige answered this in a comment:
background download events don't fire on a simulator. You can only test this on a real device
And to expand a bit, here's a guide for testing background session code:
https://forums.developer.apple.com/message/42353#42353
In my case, the cause of this was that I was using uploadTask(withStreamedRequest:...), which is not compatible with background URL sessions. I switched to use uploadTask(with:request, fromFile:...) instead and everything started working.