Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 77050

How do I create a periodic background job for iOS?

$
0
0

I am creating an app for a customer used by their staff which requires the ability to send data back to a main repository via an API. If there is no internet connection the data is flagged, and a periodic background job will check for outstanding data requiring uploading if a connection is available.

I have this working for the Android version of the application using a dependency service (I'm following the Microsoft architecture example from here https://docs.microsoft.com/en-us/xamarin/xamarin-forms/enterprise-application-patterns/).

When the app starts it calls my android implementation:-

public void SetupBackgroundSync()
        {
            Context context = Application.Context;
            var schedule = 30;

            using (var manager = (AlarmManager)context.GetSystemService(Context.AlarmService))
            {
                var syncIntent = new Intent(context, typeof(BackgroundSync));
                var pendingIntent = PendingIntent.GetService(context, 0, syncIntent, PendingIntentFlags.CancelCurrent);
                manager.SetRepeating(AlarmType.RtcWakeup, 1000 * 60 * schedule, 1000 * 60 * schedule, pendingIntent);
            }
        }

I can't seem to find a good example of how to do this for iOS. I've read the documentation on the background task options and it seems I would be looking at a Long Running Task - but it seems 'hacky' to have a timer within that to check for data I need to send back to an API every 30 minutes.

Does anybody have any examples/suggestions I could use?


Viewing all articles
Browse latest Browse all 77050

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>