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