-
Notifications
You must be signed in to change notification settings - Fork 23
Conversation
async Task InitializeBackgroundTasks() | ||
{ | ||
if (await Xamarin.ExposureNotifications.ExposureNotification.IsEnabledAsync()) | ||
await Xamarin.ExposureNotifications.ExposureNotification.ScheduleFetchAsync(); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
Xamarin.ExposureNotifications.ExposureNotification.Init(); | ||
|
||
MainPage = new AppShell(); | ||
|
||
_ = InitializeBackgroundTasks(); |
There was a problem hiding this comment.
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.
Potentially fixes part of #44