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

Init() is not working on iOS due to Xamarin.iOS bug in current stable release. #44

Closed
pavshr opened this issue May 26, 2020 · 8 comments

Comments

@pavshr
Copy link

pavshr commented May 26, 2020

Hello,

I was investigating the functionality of Init() API on iOS using cross-platform Xamarin.ExposureNotification library, and see that it does not work as it is intended to.

During my tests, I discovered that the background task is not scheduled at all and in fact is never called from the background. It basically means that UpdateKeysFromServer(), which is perhaps one of the most important APIs that allows to detect exposures regularly, is not called from background. In our project, we call Xamarin.ExposureNotifications.ExposureNotification.Init() from the AppDelegate's FinishedLaunching() method.

So I implemented the scheduling task myself, the same way it is done by you guys in the Init() API but without PlatformIsEnabled() check and with hardcoded task ID for our project (bundle id + ".exposure-notification"). I did it to secure that the task would be registered by BGTaskScheduler and executed by iOS not depending on any conditions.

By doing this, finally, I spotted in VS debug console the execution of the task from the background. However, it failed with an exception with the following error message:

Cannot create an instance of BackgroundTasks.BGTask because it is an abstract class

Further search led me to this issue in Xamarin.iOS project: xamarin/xamarin-macios#7456

As I see it, the way I implemented the task by reflecting how it is done in the cross-platform Xamarin.ExposureNotification library will not work due to the bug in current Xamarin.iOS release. Which means that until the fix xamarin/xamarin-macios@c2a220d appears in the stable, or at least the next preview release, the task will not be properly scheduled and executed in the background using the new iOS 13 BGTaskScheduler.

I would really like to hear some thoughts about this issue from Xamarin.ExposureNotification dev team. The way I see it at the moment, it is not possible to release Xamarin.ExposureNotification library without coordination with the Xamarin.iOS release that will include the fix xamarin/xamarin-macios@c2a220d. It looks also that it is not possible to implement a workaround using deprecated API as proposed in xamarin/xamarin-macios#7456 (comment) by @brminnick since we need to do it iOS 13 way via BGTaskScheduler in order to specify the id of the task. And this is the desired way to schedule the task in the background because only this way iOS ensures priority and more time for execution when executing this task:

The BackgroundTask framework detects apps that contain the Exposure Notification entitlement and a background task that ends in exposure-notification. The operating system automatically launches these apps when they aren’t running and guarantees them more background time to ensure that the app can test and report results promptly.

src: https://developer.apple.com/documentation/exposurenotification/building_an_app_to_notify_users_of_covid-19_exposure

Thank you!

@brminnick
Copy link

@mandel-macaque Do you know which version of Xamarin.iOS does/will include the bug fix for BGTask?

@dalexsoto
Copy link
Member

dalexsoto commented May 26, 2020

Hello @pavshr and @brminnick the fix you are looking for is included in our vNext builds of Xamarin.iOS at the moment you would need a build from our d16-7 the following come from today's HEAD in order to unblock you:

@pavshr
Copy link
Author

pavshr commented May 26, 2020

Thank you, much appreciated 👍

@dalexsoto
Copy link
Member

Hello @pavshr and @brminnick, we have new candidate builds based on our current stable d16-6 + the needed fix and you can find them here

Please let us know if these works for you.

@Redth
Copy link
Member

Redth commented May 27, 2020

Closing this as we have a workaround, and a plan. Thanks all!

@Redth Redth closed this as completed May 27, 2020
@brminnick
Copy link

FYI - this fix is now available in the current Preview Channel in Xamarin.iOS v13.20.0.22

@dalexsoto
Copy link
Member

dalexsoto commented Jun 8, 2020

@brminnick The fix is also included in the current released stable channel Xamarin.iOS 13.18.2.1 in both windows and Mac

@pavshr
Copy link
Author

pavshr commented Jun 8, 2020

Yes, thank you again, we are now using stable release 13.18.2.1 to build and iOS 13 BGScheduling is not an issue anymore.

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

No branches or pull requests

4 participants