Questions on periodic background tasks for Android and iOS

Hi all,

I am planning to start my first Xamarin.Forms project soon. I have been working with UWP for a long time, and the background tasks are pretty awesome.

To me, it's not entirely clear if the following use case would be achievable:

  • Run a background task (meaning that the app is NOT open) every ~15 minutes.
  • Fetch data from a remote server (small JSON file).
  • Some logic that will check the data and show a notification to the user in some cases.
  • Ideally also update the content of the app's widget.

I saw some documentation for Xamarin.Android related to Services, but for iOS it's unclear if this would be achievable.

Can someone point me to the correct documentation, or if the above scenario is possible for both iOS and Android?

Kind regards,
Niels

Answers

  • SzbestaSzbesta Member ✭✭✭

    @Niels9001 said:
    I saw some documentation for Xamarin.Android related to Services, but for iOS it's unclear if this would be achievable.

    https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-techniques/ There are some techniques for iOS. Hope it helps :D

  • Christophe_FauconChristophe_Faucon USUniversity ✭✭

    In Android you can and it should generally work alright. On some phones if the user doesn't open the app for 3'ish days then you won't be able to send notifications anymore, you'll need to get your app off of the "optimization" list.

    In iOS you can do that and it should work quite well. Essentially schedule a background task to run every x units of time (15 minutes is really frequent, it's unlikely that you actually need that, and I think iOS will slow you down to an hour or so), then from the background you have 30'ish seconds, do your fetch, schedule your notifications and release control.

  • @Christophe_Faucon said:
    In Android you can and it should generally work alright. On some phones if the user doesn't open the app for 3'ish days then you won't be able to send notifications anymore, you'll need to get your app off of the "optimization" list.

    In iOS you can do that and it should work quite well. Essentially schedule a background task to run every x units of time (15 minutes is really frequent, it's unlikely that you actually need that, and I think iOS will slow you down to an hour or so), then from the background you have 30'ish seconds, do your fetch, schedule your notifications and release control.

    Can you explain how to do it on iOS please? or provide some examples.

  • JohnHJohnH GBMember ✭✭✭✭✭

    @Martin_Opde said:
    Can you explain how to do it on iOS please? or provide some examples.

    There is a link posted immediately above the post you replied to, you should take a look.

Sign In or Register to comment.