Forum Xamarin.Forms

Background task with completion handler is not working(IOS)?

DharumaRajDharumaRaj USMember ✭✭
edited January 2017 in Xamarin.Forms

Hello, I'm working on a project where I want to run a long running background task (Xamarin forms ios). I used Background task with completion handler, but the problem is, it works only while debugging the application. Here is my code :
Task.Factory.StartNew(() => { DidEnterBackgroundId = UIApplication.SharedApplication.BeginBackgroundTask(() => { UIApplication.SharedApplication.EndBackgroundTask(DidEnterBackgroundId); }); while (!_backgroundEntryTime) { BackgroundUpdates.UpdateCurrentStatus(); BackgroundUpdates.BeginLocalToServerSync(); } UIApplication.SharedApplication.EndBackgroundTask(DidEnterBackgroundId); });
can anyone help me with this.


  • ChristianMuehleChristianMuehle DEUniversity
    On the first look the code seems ok, I have to point out that I'm also new to iOS...
    But if you never leave the while loop, at a given point iOS should cancel the task on its own. This is of course not the desired behaviour/way to do it.

    I'm not sure what you exactly mean with completion handler, the handler you pass to beginbackgroundtask is used as "pre timeout event" not to complete the tasks.
  • DharumaRajDharumaRaj USMember ✭✭

    @ChristianMuehle Is it possible to perform timely operations ,like updating data to server at an interval of 10min even when the app is closed??

  • ChristianMuehleChristianMuehle DEUniversity
    edited January 2017

    I guess yes, according to this you would need to use "Background Fetch".

    So far I did not use this I´m still working on some of the basics of our iOS App (we started and published Android first)

Sign In or Register to comment.