Skip to content
This repository has been archived by the owner on Dec 3, 2024. It is now read-only.

Improvements to the Fetch #45

Merged
merged 12 commits into from
May 26, 2020
Merged

Improvements to the Fetch #45

merged 12 commits into from
May 26, 2020

Conversation

mattleibow
Copy link
Contributor

Potentially fixes part of #44

async Task InitializeBackgroundTasks()
{
if (await Xamarin.ExposureNotifications.ExposureNotification.IsEnabledAsync())
await Xamarin.ExposureNotifications.ExposureNotification.ScheduleFetchAsync();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The app now explicitly requests the fetch scheduling. This way, the app can decide when it wants to and after what checks.

@@ -72,30 +77,58 @@ static Task PlatformScheduleFetch()

void scheduleBgTask()
{
if (ENManager.AuthorizationStatus != ENAuthorizationStatus.Authorized)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The user has not permitted this, so it will popup. Also, if the user does not want this, then no need to schedule.

Copy link
Member

Choose a reason for hiding this comment

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

This means the app should later try and schedule again... After the user is prompted and does enable it?

iOS will cancel a background task if it takes too long
keyFiles.Select(k => new NSUrl(k, false)).ToArray());
keyFiles.Select(k => new NSUrl(k, false)).ToArray(),
out var detectProgress);
cancellationToken.Register(detectProgress.Cancel);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cancel the progress when the OS tells it to.

@mattleibow mattleibow merged commit fb7d888 into master May 26, 2020
@mattleibow mattleibow deleted the dev/fetch-split branch May 26, 2020 21:12
Xamarin.ExposureNotifications.ExposureNotification.Init();

MainPage = new AppShell();

_ = InitializeBackgroundTasks();
Copy link

@brminnick brminnick May 27, 2020

Choose a reason for hiding this comment

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

It is a bad practice to not await a Task. Non-awaited Tasks don't re-throw exceptions. I've gone into more detail about it in this write-up.

The easiest fix is to change async Task InitializeBackgroundTasks() to async void InitializeBackgroundTasks(). If you're uncomfortable using async void, I recommend using the SafeFireAndForget extension method.

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

Successfully merging this pull request may close these issues.

3 participants