Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
I'm making an app which relies on syncing files though Dropbox.
It works perfectly (syncs, downloads, uploads) when running on the iOS Simulator, but when I run it on my actual device I get the cocoa 516 error (NSFileWriteFileExistsError
). Even if I clear both device and simulator and reinstalls.
Any idea on how to solve it?
2015-05-18 23:27:19.385 Home Alone[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 Home Alone[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=/private/var/mobile/Containers/Bundle/Application/BCF55F91-BAD1-4E01-B8A9-3C925749121B/Home Alone.app/Units.txt}
[ Cross-linking for reference: https://stackoverflow.com/questions/30313546/dropbox-sdk-for-ios-works-on-simulator-not-on-actual-de... ]
I posted an answer on your StackOverflow question a little while ago. Can you check if that was the issue?
Ah, I just noticed you did mention here that you cleared the device in this post. Can you add some logging to check the destination path explicitly and post the output then?
Hi Greg, appreciate the replies. I've been tearing my hair out tonight over the issue, but I'll try to do some logging tomorrow and post the results.
Hi again, I did some testing using NSFileManager. I Added this piece of code before downloading the file into the path:
if fileManager.fileExistsAtPath(localPath) {
println("File exists")
} else {
println("File does not exist")
}
On the simulator it prints "file exists", but it downloads the file to the desired location anyways, just overwriting the existing file. On my actual device it prints "file exists", but is unable to overwrite.
So i tried this:
if fileManager.fileExistsAtPath(localPath) {
println("File exists")
fileManager.removeItemAtPath(localPath, error: nil)
} else {
println("File does not exist")
}
(This code twice in a row, to check if file was removed successfully)
On simulator i get: File exists, File does not exist.
So again, simulator working as expected.
On iPhone i get: File exists, File exists. -> (so still not able to download the item).
The error I get (when I'm not just setting error: nil), is the following on iPhone:
Error Domain=NSCocoaErrorDomain Code=513 "The operation couldn’t be completed. (Cocoa error 513.)" UserInfo=0x17407bf00 {NSFilePath=/private/var/mobile/Containers/Bundle/Application/28F41502-82FC-425D-AF49-31AF48A789E6/Home Alone.app/Units.txt, NSUserStringVariant=(Remove), NSUnderlyingError=0x1740578b0 "The operation couldn’t be completed. Operation not permitted"}
So it turns out permission issues with my chosen directory was the problem. Simulator just did not care about permissions, or does not use the same set of rules as the actual device as to where the user is allowed to edit the files. I got it working by using the default app documents folder, found by using applicationDocumentsDirectory()
instead.
Great, I'm glad to hear you were able to sort this out.
Hi there!
If you need more help you can view your support options (expected response time for a 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!