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

Add background app refresh support #892

Merged
merged 3 commits into from
May 15, 2023
Merged

Conversation

stefanceriu
Copy link
Member

@stefanceriu stefanceriu commented May 15, 2023

This PR add support for background app refreshes.

The app currently stops syncing after a background task that starts when the app resigns active expires. We will now also schedule a background refresh task to run 30 seconds after this happens (just a suggestion for the system). When that happens the sync is restarted. It will attempt to run for a maximum or 10 sync responses or 10 seconds and then shut down again.

How to test this amazing piece of kit:

  1. Run on a real device, simulators are not supported
  2. Put a breakpoint right after scheduling the task -> Successfully scheduled background app refresh task
  3. Execute this debugger command e -l objc -- (void)[[BGTaskScheduler sharedScheduler] _simulateLaunchForTaskWithIdentifier:@"io.element.elementx.background.refresh"]
  4. Continue the execution
  5. See the background task getting invoked and profit

(https://developer.apple.com/documentation/backgroundtasks/starting_and_terminating_tasks_during_development)

@stefanceriu stefanceriu requested a review from a team as a code owner May 15, 2023 08:46
@stefanceriu stefanceriu requested review from Velin92 and removed request for a team May 15, 2023 08:46
@github-actions
Copy link

github-actions bot commented May 15, 2023

Warnings
⚠️ Some of the commits are missing ticket numbers. Please consider squashing all commits that don't have a tracking number.

Generated by 🚫 Danger Swift against 8316038

@@ -84,6 +84,9 @@ final class AppSettings {
/// that don't yet have an officially trusted proxy configured in their well-known.
let slidingSyncProxyURL: URL? = nil

/// The task identifier used for background app refresh. Also used in main target's the Info.plist
let backgroundAppRefreshTaskIdentifier = "io.element.elementx.background.refresh"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't we use the InfoPlistReader for this value here? So the string is always tied (don't think we are changing bundle name, but for for forks could be useful)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about it but with multiple task identifiers in that plist array you wouldn't actually know which one's which

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wha if we make sure that the plist arrat is always ordered in a certain way?
I guess a comment in the .yml on the expected order could help

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that's finicky and can lead to pretty bad bugs. Better to be safe than sorry.

Copy link
Member

@Velin92 Velin92 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@sonarcloud
Copy link

sonarcloud bot commented May 15, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@stefanceriu stefanceriu merged commit d574c0b into develop May 15, 2023
@stefanceriu stefanceriu deleted the stefan/backgroundAppRefresh branch May 15, 2023 10:06
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

Successfully merging this pull request may close these issues.

2 participants