Background Transfer Service RRS feed

  • Question

  • User360243 posted

    Hi, I working on a Xamarin Forms App and need to upload and download some data in background while app is not being in use. I understand background services are implemented differently on each platform and I am starting from iOS.

    So I have gone through the documentation of Background Transfer Service https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-walkthroughs/background-transfer-walkthrough but I am unable to understand where to write the download tasks for upload. I have implemented NSUrlSession, NSUrlSessionDownloadDelegate but unable to figure how can I initiate some tasks to download files.

    Is there any complete sample exists anywhere? I have checked the SimpleBackgroundTransfer sample but its actually using UI to kick-off the download task but in my case, the app itself should kickoff these uploads and downloads in background.

    Any help?

    Thursday, January 3, 2019 6:04 PM

All replies

  • User369979 posted

    What you post means a download or upload network task can be persisting event if app has run into background or terminal state. It needs to start this task when app is on the foreground state. But if your app has been on background state, it can't start a download or upload task as you want. iOS has its own background mode with its own system policy. Refer to this docementation: https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ for more details about iOS's background service.

    Friday, January 4, 2019 10:03 AM
  • User360243 posted

    Thanks for your reply. Here is what I am trying to achieve:

    1. Listen to location changes regardless of app is in running, background or suspended state.
    2. On a certain location, download few files from server regardless of app is in running, background or suspended state.

    I've done the reading on above link you posted but I'm unable to figure out which part of the code will host the download methods.. is it AppDelegate or NSUrlSessionDownloadDelegate or somewhere else?

    If you read this https://docs.microsoft.com/en-us/xamarin/ios/app-fundamentals/backgrounding/ios-backgrounding-walkthroughs/background-transfer-walkthrough it mentions

    The following code defines a task that can be used to download an image from a URL. We kick off the task by calling CreateDownloadTask on our background session, and passing in the URL request:

    But where do I put this code and how do I call this method - sadly they don't tell.

    Friday, January 4, 2019 11:01 PM