You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.

Forum Discussion

Jon B.1's avatar
Jon B.1
Collaborator | Level 9
3 years ago

Background download from app extension in SwiftyDropbox

 

Hi -- my macOS app was working fine when I was downloading from Dropbox in the main app, but once I added download calls from my FileProvider helper app, I started getting a string of errors.

First, in order to let both components talk to each other, I had to create my own transport client with the shared container identifier, otherwise keeping the default values:

 

            let transportClient = DropboxTransportClient(accessToken: "", baseHosts: nil, userAgent: nil, selectUser: nil,

                                                         sessionDelegate: nil, backgroundSessionDelegate: nil,

                                                         longpollSessionDelegate: nil, serverTrustPolicyManager: nil,

                                                         sharedContainerIdentifier: GROUP_CONTAINER_NAME, pathRoot: nil)

            DropboxClientsManager.setupWithAppKeyDesktop("oc..........sn", transportClient: transportClient)

 

(Note that inside the setupWithAppKeyDesktop calls, the OAuth class puts its own accessTokenProvider into the DropboxTransportClient, overwriting the dummy access token generated by the above call.  This works -- I successfully connect to Dropbox and all my foreground Dropbox calls work; it's only file downloads which produce the background session errors.)

 

After this change, I started seeing errors in both my main program and my extension.

 

022-01-14 22:32:26.846998+1100 EMPSecure[3620:78577] BackgroundSession <E635FAD8-8431-4A6B-81AC-4C5C7163B8F6> an error occurred on the xpc connection to setup the background session: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named com.apple.nsurlsessiond" UserInfo={NSDebugDescription=connection to service on pid 0 named com.apple.nsurlsessiond}

2022-01-14 22:32:26.847475+1100 EMPSecure[3620:79841] BackgroundSession <E635FAD8-8431-4A6B-81AC-4C5C7163B8F6> connection to background transfer daemon interrupted

2022-01-14 22:32:26.847552+1100 EMPSecure[3620:79858] BackgroundSession <E635FAD8-8431-4A6B-81AC-4C5C7163B8F6> connection to background transfer daemon invalidated

 

These errors occur repeatedly -- the last two more often than the first one -- from both the main process and the FileProvider app extension.  If it were just a matter of the app-ex not being able to cope with an API restriction, I'd expect that to fail while the main process succeeded; it looks like it's a problem on both sides.

 

Any ideas what I'm doing wrong?  Do I need to define my own session delegates, change my entitlements, or something else?

(BTW, I can't check the appropriate classes in the SwiftyDropbox documentation; since the 8.2.1 release the left-hand column of https://dropbox.github.io/SwiftyDropbox/api-docs/latest/ , with the class definitions, is not working.)

 

 

  • Thanks for writing this up. First, for reference, can you let me know what version of SwiftyDropbox you have installed? If you're not using the latest version, currently v8.2.1, please upgrade to that and let me know if you're still seeing this issue. If so, please also share the snippet of code you're running to do the download that triggers this.

     

    And thanks for letting us know about the issue with the documentation sidebar as well. I'll report that to the team.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Thanks for writing this up. First, for reference, can you let me know what version of SwiftyDropbox you have installed? If you're not using the latest version, currently v8.2.1, please upgrade to that and let me know if you're still seeing this issue. If so, please also share the snippet of code you're running to do the download that triggers this.

     

    And thanks for letting us know about the issue with the documentation sidebar as well. I'll report that to the team.

    • Jon B.1's avatar
      Jon B.1
      Collaborator | Level 9

      Turns out I've been building against an old version (6.0.3); I'll upgrade to 8.2.1 and get back to you!

       

      For what it's worth, the download code is fairly basic at this point:

       

              logger.log("dbx_downloadWithProgress: Downloading" + filePath)

              let destination: (URL, HTTPURLResponse) -> URL = { temporaryURL, response in

                  return destURL

              }

                  self.client?.files.download(path: filePath, overwrite: true, destination: destination)

                      .response { response, error in

                          if let (responseMetadata, responseURL) = response {

                              completionHandler(responseURL, nil)

                          } else if let error = error {

                              print(error)        // TBD: error handling!

                              self.logger.log("dbx_downloadConfig ERROR: \(error)")

                              completionHandler(nil, error)       // TBD: need to map the passed-in error to a file-provider one

                          }

                      }

                      .progress { progressData in

                          // TBD:  need to pass in and implement progress display callback

                          self.logger.log("dbx_downloadConfig PROGRESS: \(progressData)")

                          print(progressData)

                  }

       

      • Jon B.1's avatar
        Jon B.1
        Collaborator | Level 9

        Just want to confirm that upgrading to 8.2.1 fixed the main problem!  There were additional issues with the downloaded temp files not saving and opening successfully, but those were down to a quirk of the Apple FileProvider -- it was making a "file modified" call to update a "file last used" field immediately upon opening, and I hadn't implemented that yet.  But that's just unclear Apple documentation; the Dropbox code worked fine.

  • Jon B.1's avatar
    Jon B.1
    Collaborator | Level 9

    Further details on this:

    I know the app group is working; I've been able to access the app group's folder under Group Containers from both the main app and the extension.

     

    Whether I have the transport client set up with the group ID or not, download requests from the main app succeed *until* the extension is initialised.  It definitely requires both of them to be attempting to use the session to get the problem.

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

5,887 PostsLatest Activity: 2 hours ago
326 Following

If you need more help you can view your support options (expected response time for an email or ticket is 24 hours), or contact us on X or Facebook.

For more info on available support options for your Dropbox plan, see this article.

If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!