Dropbox Sync API iOS copy files to app documents

末鹿安然 提交于 2020-01-06 15:19:11

问题


Does the Dropbox Sync API allow for copying directories or files from Dropbox into the app sandbox directories?

I was excited to use the Dropbox Sync API and use Dropbox to manage media assets between my OS X machine and an iPad running my app.

I integrated the Sync API pretty quickly and am able to open files and save them in to Dropbox again.

Because my app is already set up with many many calls to dynamically load media assets, it would add unnecessary complexity to try to open all those assets from the Dropbox filesystem. My intention was to use the Sync API to determine if there are updated assets and then copy them in to one of my application directories.

But it seems that nearly all the objects returned using the Sync API are DBObjects, and I can't perform normal NSFilesystem file operations such as copy. Also the DBObjects seem to have no copy functions themselves.

Is there any way to do this without resorting to the CorecAPI?

Example, for an arbitrary file type called story

//get a list of stories and put them in an array
    DBPath *storyPathDB = [[DBPath root] childPath:@"/storyBundlesDB"];
    NSArray *listOfStoriesDB = [[DBFilesystem sharedFilesystem] listFolder:storyPathDB error:nil];
    for (DBFileInfo *story in listOfStoriesDB)
    {
        //now I can list out the path of my stories, but that's about it...
        DBPath *storyPath = story.path;
        NSLog(@"%@",storyPath.stringValue);
        //How can I treat these stories whether they are directories or .mov, .png, and copy them to my app directory? 
    }

I saw this question here Data syncing with DropBox API and iOS where people suggested using the SyncAPI for exactly this purpose, but it seems as if noone on that thread had actually tried it.


回答1:


You could use readData to read the contents of the file and then write it to another location, if you can't directly use the DBFile objects.

Note that if you want to get notifications when a file (in Dropbox) changes, you'll need to hold that file open. Essentially, files are only updated when you hold the file open, get a notification that there's newer content available, and then call update.



来源:https://stackoverflow.com/questions/18494546/dropbox-sync-api-ios-copy-files-to-app-documents

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!