1 Reply
      Latest reply on Dec 7, 2018 1:43 AM by eskimo
      yoursco Level 1 Level 1 (0 points)

        Our users select photos and videos to upload to our backend system. Currently, we have to:

         

        1. Write each PHAsset to disk

        2. Schedule the background upload using NSURLSession

        3. If they run out of disk space or close the app before we write it to disk, we have a bunch of alternate paths (batching uploads, local notifications to nudge them to reopen the app until the batch of files is ready to be uploaded)

         

        To make this easier on ourselves, we first send metadata about the assets to our server so that the app can check the server for assets it should be uploading.

         

        Would it be safe/possible to use the background fetch API to check our backend for pending uploads, and then return upload requests (instead of download requests)? Would we be able to write the assets to disk during the application:performFetchWithCompletionHandler: callback?

         

         

        • Re: Can the background fetch API be used to initiate an upload operation?
          eskimo Apple Staff Apple Staff (10,285 points)

          Would it be safe/possible to use the background fetch API to check our backend for pending uploads, and then return upload requests (instead of download requests)?

          I’m not entirely sure what you’re getting at here, but you seem to be asking whether background fetch requires you to do a download operation.  If so, the answer is a very clear “No.”  Despite it’s name, background fetch is not connected to the network at all and you can do whatever you want in response to that callback.

          Would we be able to write the assets to disk during the application:performFetchWithCompletionHandler: callback?

          Yes, with caveats.  When you get the background fetch callback you have a very limited amount of time to do work.  By default it’s a few seconds, although you can extend that a little bit using a UIApplication background task (see my UIApplication Background Task Notes post for more).  If that’s enough time to export your assets, you’re all set.  If not, you’ll need to think carefully about how you approach this.

          Share and Enjoy

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