2012-01-15 3 views
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"); 
      } 
     } 
    } 
} 
+0

유용한 게시물 찾기 : http://stackoverflow.com/questions/5950168/a-simple-sync-with-the-iphone-dropbox-api – mstottrop

답변

2

이 의심이 항상 self.metaData.lastModifiedDatefileDate 동일 또는 fileDate이 두 날짜의 항상 이전 중 하나를 나에게 의미 true로 평가하고있다

if ([[fileDate earlierDate:self.metaData.lastModifiedDate]isEqualToDate:fileDate]) { 

.

정직하게 말하면, 나는 이러한 조건문을 분석하는 데 어려움을 겪고 있습니다. 다른 방식으로 평가를 시도하면 어떻게됩니까? 예를 들면 다음과 같습니다.

if (nil == fileDate || fileDate.timeIntervalSinceReferenceDate < self.metaData.lastModifiedDate.timeIntervalSinceReferenceDate) 
{ 
    [self.restClient loadFile:[NSString stringWithFormat: @"%@/%@", destDir, filename] 
         intoPath:address]; 
    NSLog(@"Downloading"); 
} 
else if (nil != fileDate && fileDate.timeIntervalSinceReferenceDate > self.metaData.lastModifiedDate.timeIntervalSinceReferenceDate) { 
    [[self restClient] uploadFile:filename toPath:destDir fromPath:address]; 
    NSLog(@"Uploading"); 
} 

날짜가 동일하면 두 가지 모두 수행하지 않으려한다고 가정합니까?