0

I am working on a project involving an iOS app communicating with another device by way of syncing data through Dropbox.

It works perfectly fine when I run the software on the iPhone Simulator (it syncs, uploads, downloads without issues), but when I load it onto my actual device, I get load/save errors.

The app on both the simulator and iPhone was successfully linked to my Dropbox account.

Some errors when I try do load requests:

2015-05-18 23:27:19.385 [2218:923269] [ERROR] DBRequest#connectionDidFinishLoading: error moving temp file to desired location: The operation couldn’t be completed. (Cocoa error 516.)

2015-05-18 23:27:19.387 [2218:923269] [WARNING] DropboxSDK: error making request to /1/files/dropbox/Projekt 2 (1)/Program/Units.txt - (516) Error Domain=NSCocoaErrorDomain Code=516 "The operation couldn’t be completed. (Cocoa error 516.)" UserInfo=0x174077700 {path=/Projekt 2 (1)/Program/Units.txt, destinationPath=/...}

Samples of the dropbox related code in my app:

In AppDelegate.swift:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    let session = DBSession(appKey: "myAppKey", appSecret: "myAppSecret", root: kDBRootDropbox)
    DBSession.setSharedSession(session)
    ...
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
    if DBSession.sharedSession().handleOpenURL(url) {
        if DBSession.sharedSession().isLinked() {
            // Linking was successfull.
        }
        return true
    }
    return false 
}

In ViewControllerCausingErrors.swift:

class ViewControllerCausingErrors: DBRestClientDelegate {

    var dbClient = DBRestClient()

    override func viewDidLoad() {
        super.viewDidLoad()
        self.dbClient = DBRestClient(session: DBSession.sharedSession())
        self.dbClient.delegate = self
    }

    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated: animated)
        if !DBSession.sharedSession().isLinked() {
            DBSession.sharedSession().linkFromController(self)
        }
    }
}

Chunk of code i use to download a file, elsewhere in the VC

if let localPath = NSBundle.mainBundle().pathForResource("Units", ofType: "txt") {
    // Download file from Dropbox to local path.
    let dropboxPath = Constants.Dropbox.Download.UnitFilePath
    self.dbClient.loadFile(dropboxPath, intoPath: localPath)
}

Any help is greatly appreciated.

4
  • [Cross-linking for reference: dropboxforum.com/hc/communities/public/questions/… ]
    – Greg
    Commented May 18, 2015 at 23:06
  • Have you found a solution? Could you provide a code?
    – Fengson
    Commented May 29, 2015 at 11:34
  • @Fengson Yes I did. If you want to know what caused the problem and how I solved it, check out my post on the Dropbox forums: Link
    – l_priebe
    Commented May 30, 2015 at 19:09
  • Already did but this didn't help me, getting the same error. Oh well, thanks anyway.
    – Fengson
    Commented May 31, 2015 at 9:01

2 Answers 2

1

According to the iOS documentation, error code 516 is:

NSFileWriteFileExistsError = 516,

It sounds like there's a file at the supplied localPath on the device (called destinationPath in the error), but not on the simulator, causing loadFile to not be able to write the file from the download.

0

I think problem is in the NSBundle.mainBundle().pathForResource("Units", ofType: "txt"). NSBundle is used in simulator but not in actual device. You just place Units.txt in your loadFile function

self.dbClient.loadFile(dropboxPath, intoPath: "Units.txt")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.