Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

Ricky B.5's avatar
Ricky B.5
New member | Level 1
10 years ago

SDK1.3.13 and Swift

Hello,

I try to develop a very simple application connected with DropBox.
I am looking for example in swift (not in objective C), could you please help me ?

Need to connect, and retrieve list of files in a Dropbox folder.

Many thanks,
Sébastien

4 Replies

Replies have been turned off for this discussion
  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    We don't currently have a Swift sample app for the iOS Core SDK, but it should be possible to use it in a Swift app. There's a blog post here about how to use the Sync SDK in a Swift app:

    https://blogs.dropbox.com/developers/2014/09/swift-apps-with-dropbox/

    I believe the same basic steps should work with the Core SDK.

    Once you have the SDK installed, you should be able to use it as expected. If you run into any specific issues, feel free to post the code and errors here.

  • Ricky B.5's avatar
    Ricky B.5
    New member | Level 1
    10 years ago

    hello,
    thanks for your reply, I make some progress because i discovered an example (https://github.com/tkunstek/elevenchat/tree/master/ElevenChat)

    Now i am facing an issue when I try to loadmetadata
    loadedMetadata failed with error: Error Domain=dropbox.com Code=400 "The operation couldn’t be completed. (dropbox.com error 400.)" UserInfo=0x7fe6f1411c10 {path=/, error=App folder (sandbox) access attempt failed because this app is not configured to have an app folder. Should your access type be 'dropbox' instead?}

    my code below:

    // dropbox rest client
    private var dbRestClient: DBRestClient?
    
    @IBAction func btconnect(sender: AnyObject) {
        if !DBSession.sharedSession().isLinked() {
            // should let use know why ayou are asking for dropbox permissions
            // now ask for permission
            DBSession.sharedSession().linkFromController(self)
        }
        if dbRestClient == nil {
            dbRestClient = DBRestClient(session: DBSession.sharedSession())
            dbRestClient!.delegate = self
        }
    }
    
    @IBAction func btList(sender: AnyObject) {
        dbRestClient?.loadMetadata("/")
    }
    
    func restClient(client: DBRestClient!, loadedMetadata metadata: DBMetadata!){
        if (metadata.isDirectory) {
            println("Folder \(metadata.path) contains:")
    
            for FILE in metadata.contents {
                println(" \(FILE.filename)");
            }
        }
    }
    
    func restClient(client: DBRestClient!, loadMetadataFailedWithError error: NSError!){
        println("loadedMetadata failed with error: \(error)")
    }
    

    any idea ?
    Thanks
    Sébastien

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    10 years ago

    The error message is indicating that you have the wrong root set. You set that when you construct your DBSession using DBSession:initWithAppKey:appSecret:root:. It sounds like you're supplying kDBRootAppFolder when you should be supplying kDBRootDropbox to match your app registration.

  • Ricky B.5's avatar
    Ricky B.5
    New member | Level 1
    10 years ago

    many thanks, is was exactly my issue...

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    // setup dropbox
    let dbSession = DBSession(appKey: "blabla", appSecret: "blabla", root: kDBRootDropbox) //previous value kDBRootAppFolder
    DBSession.setSharedSession(dbSession)
    return true
    }

About Dropbox API Support & Feedback

Node avatar for Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

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, Facebook or Instagram.

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!