ios上Dropbox Sync api的文件同步问题
我在ios上创建了一个文件,并将其添加到dropbox sync api以与dropbox帐户同步 后来当我编辑文件时,我编辑的文件没有显示在dropbox上。这就是我所做的 我使用ios FileManager创建了一个文件,如下所示:ios上Dropbox Sync api的文件同步问题,ios,sync,dropbox-api,Ios,Sync,Dropbox Api,我在ios上创建了一个文件,并将其添加到dropbox sync api以与dropbox帐户同步 后来当我编辑文件时,我编辑的文件没有显示在dropbox上。这就是我所做的 我使用ios FileManager创建了一个文件,如下所示: if(![ABUtil fileExist:FILENAME]) { NSString *st = @"This is a Test"; NSData *file = [st dataUsingEncoding:NSUTF8StringEnco
if(![ABUtil fileExist:FILENAME]) {
NSString *st = @"This is a Test";
NSData *file = [st dataUsingEncoding:NSUTF8StringEncoding];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *file = [[paths objectAtIndex:0] stringByAppendingPathComponent:FILENAME];
[[NSFileManager defaultManager] createFileAtPath:
contents:file
attributes:nil];
}
然后我为它创建一个dropbox文件,如下所示:
DBAccount *account = [[DBAccountManager sharedManager] linkedAccount];
if (account) {
DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account];
[DBFilesystem setSharedFilesystem:filesystem];
if([ABUtil fileExist:FILENAME]) {
DBPath *path = [[DBPath root] childPath:FILENAME];
DBFile *file = [filesystem createFile:path error:nil];
[file addObserver:self block:^(){
NSLog(@"FILE CHANGED");
}];
}
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *file = [[paths objectAtIndex:0] stringByAppendingPathComponent:FILENAME];
NSString *string = @"Tis is a test";
[string writeToFile:file atomically:YES encoding:NSUTF8StringEncoding error:nil];
稍后,当我在ios上使用以下命令修改文件时:
DBAccount *account = [[DBAccountManager sharedManager] linkedAccount];
if (account) {
DBFilesystem *filesystem = [[DBFilesystem alloc] initWithAccount:account];
[DBFilesystem setSharedFilesystem:filesystem];
if([ABUtil fileExist:FILENAME]) {
DBPath *path = [[DBPath root] childPath:FILENAME];
DBFile *file = [filesystem createFile:path error:nil];
[file addObserver:self block:^(){
NSLog(@"FILE CHANGED");
}];
}
}
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *file = [[paths objectAtIndex:0] stringByAppendingPathComponent:FILENAME];
NSString *string = @"Tis is a test";
[string writeToFile:file atomically:YES encoding:NSUTF8StringEncoding error:nil];
dropbox目录下的文件未更改!!请帮助我如何使文件更改与dropbox同步 编辑我错了。NSString上有一个将其内容写入文件的方法。所以这一部分大概是起作用的。下一步是将该文件复制到Dropbox中 修改完本地文件后,需要调用将该文件上载到Dropbox
或者您可以完全跳过本地文件,这是Dropbox Sync API中更常见的模式。(看看同步SDK附带的Notes示例,了解如何直接编辑Dropbox文件。)为什么希望更新的文件与Dropbox同步?您正在将更新写入应用程序的文档文件夹,而不是Dropbox。谢谢您的回答。我之所以在txt文件上测试,是因为我在ios上有一个sqlite数据库文件,而且用户一直在更新数据库,我想将这个database.db文件同步到dropbox。那么,在每次数据库更新或插入之后,我是否必须调用writeContentsOfFile?addObserve如何观察整个应用程序根目录,如下所示:[[DBFilesystem sharedFilesystem]addObserver:self-forPathAndChildren:[DBPath root]块:^(){NSLog(@“FILE SYSTEM CHANGED”);};是的,每次更改文件时,您都必须将其写入Dropbox。我看不出观察员会有什么帮助。。。这只会观察Dropbox中的文件。需要观察者,以便设备B知道设备A何时更新文件。是的,您需要这样做(当文件更改时,您必须复制文件),但您已经设置的观察者应该涵盖这一点。(
[file addObserver:…]
在您共享的代码中)确定。因此,每当我更改本地文件以与Dropbox帐户同步时,我都必须调用writeContentsOfFile。我还需要添加所有文件和目录的观察者,对吗。如果device1将文件a添加到DB,device2将文件B添加到DB,它们将如何相互同步?如果device1修改了文件C,device2如何获得文件C的更新?