cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Background download from app extension in SwiftyDropbox

Background download from app extension in SwiftyDropbox

Jon B.1
Collaborator | Level 9
Go to solution

 

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.)

 

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

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.

View solution in original post

5 Replies 5

Greg-DB
Dropbox Staff
Go to solution

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
Collaborator | Level 9
Go to solution

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.

Jon B.1
Collaborator | Level 9
Go to solution

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
Collaborator | Level 9
Go to solution

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.

Greg-DB
Dropbox Staff
Go to solution

Thanks for following up. I'm glad to hear you got this working. I just wanted to report that we've fixed the SwiftyDropbox documentation.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Jon B.1 Collaborator | Level 9
What do Dropbox user levels mean?