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: 

Dropbox SDK for iOS works on simulator, not on actual device

Dropbox SDK for iOS works on simulator, not on actual device

Lasse Hammer P.
New member | Level 1

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}
7 Replies 7

Greg-DB
Dropbox Staff

[ 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?

Greg-DB
Dropbox Staff

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?

Lasse Hammer P.
New member | Level 1

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.

Lasse Hammer P.
New member | Level 1

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

Lasse Hammer P.
New member | Level 1

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"}

Lasse Hammer P.
New member | Level 1

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.

Greg-DB
Dropbox Staff

Great, I'm glad to hear you were able to sort this out.

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Lasse Hammer P. New member | Level 1
What do Dropbox user levels mean?