<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Background Session for NSURLSession in iOS in Dropbox API Support &amp; Feedback</title>
    <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221710#M11781</link>
    <description>Hi Mark, the SDK does give you the choice of using foreground or background sessions, and it sounds like you have a good understanding of the difference already. This is a bit outside the scope of Dropbox API support though, so I'm afraid I can't offer much insight myself. Hopefully there's someone with more experience with iOS development that can offer some advice. (Or, you may want to ask in a more iOS-specific forum, such as Apple's forums.)</description>
    <pubDate>Wed, 17 May 2017 20:13:54 GMT</pubDate>
    <dc:creator>Greg-DB</dc:creator>
    <dc:date>2017-05-17T20:13:54Z</dc:date>
    <item>
      <title>Background Session for NSURLSession in iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221653#M11770</link>
      <description>&lt;P&gt;I am after a little advice on background/foreground session usage. The documentation states that by default, background sessions are used for uploads and download. As I understand it, this means that the transfer can complete even if the app is no longer running. You can optionally&amp;nbsp;use foreground sessions instead, but then you lose the ability to transfer when the app is suspended or quit.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In my case, I am only uploading/downloading small files (as part of a data syncing strategy). This is mainly done in the foreground when the user adds data to the app. If the user comes out of the app, then the app asks for more time to complete any data transfers (using the&amp;nbsp;&lt;SPAN class="s1"&gt;beginBackgroundTaskWithName app delegate method). This is typically sufficient for the small size of the data involved.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="s1"&gt;So would I be better off setting sessions to run in the foreground? The only downside I can see if that if the app is quit or the network connection is lost, then the transfers will not complete.&amp;nbsp;However the&amp;nbsp;syncing code is designed to check for incomplete transfers and try again when the app is restarted, which should mitigate against this.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="s1"&gt;I am a little wary of background transfers since I am not sure how it behaves if the transfer is completed when the app is not running (and therefore my syncing code it not there to control it)...&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2019 09:22:36 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221653#M11770</guid>
      <dc:creator>Mark R.5</dc:creator>
      <dc:date>2019-05-29T09:22:36Z</dc:date>
    </item>
    <item>
      <title>Re: Background Session for NSURLSession in iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221710#M11781</link>
      <description>Hi Mark, the SDK does give you the choice of using foreground or background sessions, and it sounds like you have a good understanding of the difference already. This is a bit outside the scope of Dropbox API support though, so I'm afraid I can't offer much insight myself. Hopefully there's someone with more experience with iOS development that can offer some advice. (Or, you may want to ask in a more iOS-specific forum, such as Apple's forums.)</description>
      <pubDate>Wed, 17 May 2017 20:13:54 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221710#M11781</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2017-05-17T20:13:54Z</dc:date>
    </item>
    <item>
      <title>Re: Background Session for NSURLSession in iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221890#M11798</link>
      <description>&lt;P&gt;Hi Greg,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think part of my query does actually relate directly to the framework. If you read the 'Background Transfer Considerations' section in Apple's documentation:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/URLLoadingSystem/Articles/UsingNSURLSession.html#//apple_ref/doc/uid/TP40013509-SW44" target="_self"&gt;URL Session Programming Guide&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;then it explains what an app should do in the event that a transfer completes when&amp;nbsp;the app is not running. Specifically:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;----------------------------------&lt;/P&gt;
&lt;P&gt;In iOS, when a background transfer completes or requires credentials, if your app is no longer running, iOS automatically relaunches your app in the background and calls the &lt;CODE&gt;&lt;A class="urlLink" href="https://developer.apple.com/reference/uikit/uiapplicationdelegate/1622941-application" target="_self"&gt;application:handleEventsForBackgroundURLSession:completionHandler:&lt;/A&gt;&lt;/CODE&gt; method on your app’s &lt;CODE&gt;UIApplicationDelegate&lt;/CODE&gt; object. This call provides the identifier of the session that caused your app to be launched. Your app should store that completion handler, create a background configuration object with the same identifier, and create a session with that configuration object. The new session is automatically reassociated with ongoing background activity. Later, when the session finishes the last background download task, it sends the session delegate a &lt;CODE&gt;&lt;A class="urlLink" href="https://developer.apple.com/reference/foundation/urlsessiondelegate/1617185-urlsessiondidfinishevents" target="_self"&gt;URLSessionDidFinishEventsForBackgroundURLSession:&lt;/A&gt;&lt;/CODE&gt; message. In that delegate method, call the previously stored completion handler &lt;EM&gt;on the main thread&lt;/EM&gt; so that the operating system knows that it is safe to suspend your app again.&lt;/P&gt;
&lt;P&gt;In both iOS and OS X, when the user relaunches your app, your app should immediately create background configuration objects with the same identifiers as any sessions that had outstanding tasks when your app was last running, then create a session for each of those configuration objects. These new sessions are similarly automatically reassociated with ongoing background activity.&lt;/P&gt;
&lt;P&gt;------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Since the Dropbox framework manages&amp;nbsp;the sessions, then does it also deal with the fiddling around described above or is that left up to the app?&lt;/P&gt;</description>
      <pubDate>Thu, 18 May 2017 15:32:25 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221890#M11798</guid>
      <dc:creator>Mark R.5</dc:creator>
      <dc:date>2017-05-18T15:32:25Z</dc:date>
    </item>
    <item>
      <title>Re: Background Session for NSURLSession in iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221952#M11810</link>
      <description>I'm checking in with the team to get some information on the specifics of this in the Dropbox SDK. Thanks in advance for your patience.</description>
      <pubDate>Thu, 18 May 2017 21:44:36 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/221952#M11810</guid>
      <dc:creator>Greg-DB</dc:creator>
      <dc:date>2017-05-18T21:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: Background Session for NSURLSession in iOS</title>
      <link>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/223811#M12062</link>
      <description>&lt;P&gt;Hi Mark, sorry for the delay here. Unfortunately, the SDK doesn't expose an interface for implementing this session re-attachment behavior.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm no expert in this behavior, but if I recall, after sesion reattachment, you need to resupply a response handler to handle the upload or download that completed while your app was not running.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There's no way to do that other than to handwrite some logic in `application(_:handleEventsForBackgroundURLSession:completionHandler:)`.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You'd have to maintain some sort of map between request id and response handler there, and reinstall the handler accordingly. This would complicate the SDK interface considerably.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For that reason, the SDK simply chooses not to handle the case where the application is killed.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jun 2017 00:23:48 GMT</pubDate>
      <guid>https://www.dropboxforum.com/t5/Dropbox-API-Support-Feedback/Background-Session-for-NSURLSession-in-iOS/m-p/223811#M12062</guid>
      <dc:creator>Stephen C.14</dc:creator>
      <dc:date>2017-06-01T00:23:48Z</dc:date>
    </item>
  </channel>
</rss>

