1
我正在使用Dropbox iOS API在不同设备之间进行同步。使用下面的代码,我试图比较文件被修改为下载/上传新文件的日期。问题是,它只是下载并从不上传。任何提示?使用Dropbox iOS API和NSDate下载或上传文件不起作用
- (void)dropboxAuth {
if (![[DBSession sharedSession] isLinked]) {
[[DBSession sharedSession] link];
}
else {
NSString *filename = @"NotesList.plist";
NSString *destDir = @"/";
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *address = [documentsDir stringByAppendingPathComponent:@"NotesList.plist"];
[[self restClient] loadMetadata:@"/"];
if([[NSFileManager defaultManager] fileExistsAtPath:address]) {
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfItemAtPath:address error:&error];
NSDate *fileDate =[dictionary objectForKey:NSFileModificationDate];
if ([[fileDate earlierDate:self.metaData.lastModifiedDate]isEqualToDate:fileDate]) {
[self.restClient loadFile:[NSString stringWithFormat: @"%@/%@", destDir, filename]
intoPath:address];
NSLog(@"Downloading");
}
else if ([[self.metaData.lastModifiedDate earlierDate:fileDate] isEqualToDate:self.metaData.lastModifiedDate]) {
[[self restClient] uploadFile:filename toPath:destDir fromPath:address];
NSLog(@"Uploading");
}
}
}
}
找到一个有用的帖子:http://stackoverflow.com/questions/5950168/a-simple-sync-with-the-iphone-dropbox-api – mstottrop 2012-04-22 14:05:01