3 Replies
      Latest reply on Sep 27, 2019 1:13 AM by eskimo
      helloworldchris Level 1 Level 1 (0 points)

        Currently we are doing it the old fashioned way, using background url session that we hit whenever app does a background fetch.

        Seems like there is a better way of doing it with new framework.  Are there good Apple examples of doing that?  I haven't found any examples that do that.

         

        Do we still need to use URLSessionConfiguration.background(withIdentifier: sessionName) with all the data/session delegates, or can we instead use URLSession.shared api with a completion block?

         

        Thanks,

         

        Chris

        • Re: BGTaskScheduler for doing http tasks?
          eskimo Apple Staff Apple Staff (12,035 points)

          The BackgroundTasks framework is potentially useful for this sort of thing.  In the traditional background fetch model, you were resumed in the background but only got a small execution time allowance.  That meant you had to use a URLSession background session for your networking.  With the BackgroundTasks framework you can receive large amount of background execution time, which gives you the choice of using either a background session or a standard session, whichever you prefer.

          Which to use depends on the details of your networking.  If, for example, you’re downloading a small number of huge files, a background session would still make sense.  That’s what it was originally designed for, and it works well for that.  OTOH, if you have to do a lot of interactive back and forth with your server, a standard session is a much better choice.

          The main thing to watch out for here is expiry.  As is normal for background execution, there’s no guarantee that you’ll get all the time you need.

          Are there good Apple examples of doing that?

          I dunno about good but there is an example (-:  Check out Refreshing and Maintaining Your App Using Background Tasks.

          Share and Enjoy

          Quinn “The Eskimo!”
          Apple Developer Relations, Developer Technical Support, Core OS/Hardware
          let myEmail = "eskimo" + "1" + "@apple.com"