简体   繁体   中英

File Sync issue with Dropbox sync api on ios

I created a file on ios and add it to dropbox sync api to sync with the dropbox account.

Later when I edit the file, the file I edited did not show on dropbox. Here is what I did.

I created a file using ios FileManager like this:

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];
}

Then I create a dropbox file for it like this:

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");
        }];
    }

}

Later when I modify the file using on ios like this:

    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];

The file did not change at dropbox directory!! Please help me how to make the file change sync with the dropbox!!!

EDIT I was mistaken. There is a method on NSString to write its contents to a file. So that part is presumably working. The next step would be to copy that file into Dropbox.

When you finish modifying the local file, you'll want to call writeContentsOfFile to upload that file to Dropbox.

Or you could skip the local file altogether, which is the more common pattern with the Dropbox Sync API. (Take a look at the Notes example that ships with the Sync SDK to see how to edit Dropbox files directly.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM