Skip to content

Instantly share code, notes, and snippets.

@billymeltdown
Created November 29, 2012 14:24
Show Gist options
  • Save billymeltdown/4169422 to your computer and use it in GitHub Desktop.
Save billymeltdown/4169422 to your computer and use it in GitHub Desktop.
Can run afoul of cross-device link error
NSURL *remoteFileURL = [[self temporaryDocumentsURL] URLByAppendingPathComponent:ZTDropboxRemoteFileName];
NSURL *databaseFileURL = [[self dropboxFolderURL] URLByAppendingPathComponent:self.dbFileName];
NSError *error;
BOOL success = NO;
NSFileManager *fm = [NSFileManager defaultManager];
// if this isn't our first time, use replaceItem...
if ([databaseFileURL checkResourceIsReachableAndReturnError:&error])
{
NSURL *newItemURL;
success = [fm replaceItemAtURL:databaseFileURL
withItemAtURL:remoteFileURL
backupItemName:nil
options:0
resultingItemURL:&newItemURL
error:&error];
}
else // just do a plain-ol' copy
{
success = [fm copyItemAtURL: remoteFileURL
toURL: databaseFileURL
error: &error];
// ...
}
@billymeltdown
Copy link
Author

self.dropboxFolderURL is chosen by the user with NSOpenPanel running in Sandbox, so it is security-scoped. It's either supplied directly by the user, or retrieved from a security-scoped bookmark stored as NSData in NSUserDefaults.

@billymeltdown
Copy link
Author

When replacing an item on an attached volume, you get:

NSUnderlyingError=0x105b0abd0 “The operation couldn’t be completed. Cross-device link”

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment