cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more 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: 

Unable to list folder files in iOS Swift

Unable to list folder files in iOS Swift

ravisharma
New member | Level 2

I am facing below error when I am trying to list folder or get current account info. Please help

 

Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=https://api.dropbox.com/2/users/get_current_account, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=https://api.dropbox.com/2/users/get_current_account}

Error Domain=NSURLErrorDomain Code=-999 "cancelled" UserInfo={NSErrorFailingURLKey=https://api.dropbox.com/2/files/list_folder, NSLocalizedDescription=cancelled, NSErrorFailingURLStringKey=https://api.dropbox.com/2/files/list_folder}

 

Below the code I have tried. 

 

let client = DropboxClient(accessToken: "MYTOKEN")

        client.users.getCurrentAccount().response { (response, error) in

            if let result = response {

                print(result)

            } else if let error = error {

                print(error)

            }

        }

        

        client.files.listFolder(path: "").response(queue: DispatchQueue(label: "MyCustomSerialQueue")) { response, error in

            if let result = response {

                print(Thread.current)  // Output: <NSThread: 0x61000007bec0>{number = 4, name = (null)}

                print(Thread.main)     // Output: <NSThread: 0x608000070100>{number = 1, name = (null)}

                print(result)

            } else if let error = error {

                print(error)

            }

        }

1 Reply 1

Greg-DB
Dropbox Staff
It looks like your client object is probably going out of scope before the request can finish. Note that the actual API calls are made asynchronously, so the client object may be gone by the time the network call finishes.

Try keeping your client around instead. For example, you can use DropboxClientsManager.authorizedClient.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
What do Dropbox user levels mean?