cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done 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

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

Greg-DB
Dropboxer

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

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

Greg-DB
Dropboxer

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?

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

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.

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

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

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

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

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

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.

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

Greg-DB
Dropboxer

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

Who's talking

Top contributors to this post

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