Usman26
Usman26

Reputation: 95

Call Xamarin.Forms Dependency Service with app closed

I have developed an app using Xamarin Forms and I am trying to update notifications for each platform based on some updated data.

The flow is as follows for Android (the only difference for iOS is that it uses a background fetch):

This works fine if the app is open or the app is in the background. However, if the app is closed then the call to update existing notifications fails. This happens because Xamarin Forms has not been initialised when the app is closed, so Dependency Service can't be used which results in the notifications not getting updated.

I want to use Dependency Service because my app uses Xamarin Forms and I would like to share as much code as possible between the different platforms. Does anyone know of a way around this, whilst still using Xamarin Forms?

Upvotes: 1

Views: 468

Answers (1)

Usman26
Usman26

Reputation: 95

So, it seems like there is no way of calling Xamarin Form Dependency Service when the app is closed. However, I was able to come up with a different solution to my problem.

I had to have slightly more platform specific code to overcome the issue. What I did was instead of using Dependency Service to update my existing notifications, I gathered the required information to update the notification and sent this back to each platform. The platform would then use the information received and update the notification itself.

This means that calling to update notifications is not shared, but it is only a little bit of platform specific logic which I am comfortable with as it allows me to update notifications with the app closed.

Upvotes: 1

Related Questions