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

Background task is not working probably #14

Open
GaoMax opened this issue Mar 20, 2021 · 6 comments
Open

Background task is not working probably #14

GaoMax opened this issue Mar 20, 2021 · 6 comments

Comments

@GaoMax
Copy link

GaoMax commented Mar 20, 2021

Describe the bug
Sometimes the background task doesn't behave like it should.
If the unexpected behavior occurs, the task is dead. Launching the app is needed for it to work probably again. It happens when "Making Fake Move" is performed multiple times instead of only once.
If the expected behavior occurs, it makes a fake move and restarts the background task.

Unexpected behavior

Background task registered
Background task ended.
Making Fake Move.
Making Fake Move.
Making Fake Move.
Room Buero, Likelihood 90.4
Making Fake Move.

OR

Background task registered
Background task ended.
Making Fake Move.
Making Fake Move.
Making Fake Move.
Room Buero, Likelihood 99.6
Making Fake Move.
Making Fake Move.
Room Buero, Likelihood 99.6

Expected behavior

Background task registered
Background task ended.
Making Fake Move.
Room Buero, Likelihood 97.2
Background task registered

Smartphone (please complete the following information):

  • Tested on iOS 14.3, 14.4 and 14.5 Beta 3
  • on iPhone X and iPhone 12 Pro
@GaoMax
Copy link
Author

GaoMax commented Mar 21, 2021

Hey, since the latest commit background task has completed stopped working for me. I've used the original code, no modifications. Behavior is the same, making fake move is called multiple times and no new background task is registered.
I've tried modifying the mode, but haven't been successful. I haven't quite understood your background energy saving measures.

@GaoMax
Copy link
Author

GaoMax commented Mar 21, 2021

On further investigation it appears to be a timing problem. The multiple calls of Making Fake Move is due to the shortened threshold of remainingTime. Changing the threshold to 5-10 fixes the multiple making fake moves calls, but the task dies afterwards. Putting it at 15 makes it work most of the times, but not always, same for 20. It appears that if the phone does not move at all before background task starts, the restart of the task fails.

@st0nedB
Copy link
Owner

st0nedB commented Mar 23, 2021

Just to add some additional background info:
To keep the app alive, Apple requires to keep the Localization services running at all times. However, this draws a lot of power, even when the device is not moving and hence not changing location.
The current workaround is to move the app to background processing, which gives around 30s of processing before iOS terminates it completely. To avoid termination, the location services are switched back on and beacon ranging is performed, which keeps the app alive (aka triggering a "fake move"). Afterwards the app switches to the background again for another 30s. Location services are also switched back on when the IMU detects movement.

Increasing the threshold to trigger the fakeMove earlier will hence decrease power efficiency.

@GaoMax
Copy link
Author

GaoMax commented Mar 24, 2021

Thank you for elaborating!
This mechanism is quite ingenious.
But it seems like it is currently not working probably. Maybe Apple broke this workaround in an iOS update?
If the 30s window is used fully i.e. 1 second is left for the background task, it behaves weirdly. I couldn't find any code related bugs for this behavior. If 15s are left for the background task, it behaves correctly.

@st0nedB
Copy link
Owner

st0nedB commented Mar 24, 2021

Yes, that's definitely the first thing to investigate. Maybe I'll find time to look into it at the weekend, but I can't promise ;)
BTW: This mechanism is also why I didn't consider submitting to the AppStore. Its probably not the way Apple intents for things to work. My hope is they will give us some way to perform beacon ranging in the background in the future without using the full localization services framework. This method is great for indoor localization and actually really privacy conserving.

@GaoMax
Copy link
Author

GaoMax commented Mar 25, 2021

Sounds awesome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants