2013-05-01 4 views
0

내 응용 프로그램은 UIDocument + iCloud를 사용하여 문서를 만들고 볼 수 있습니다./Filename.db NSMetadataQuery를 사용하여 디렉토리 내의 파일 검색

  • 문서/Filename.db/파일을 - file.db이 (Filename.db이있는 디렉토리) 문서/파일 이름 내부
  • 파일을

    • 문서 : 파일은 이런 식으로 저장됩니다 .db 디렉토리가 자체 View Controller에서 올바르게로드됩니다. 다른보기 컨트롤러에서 Documents/Filename.db/File.db를 열 때 해당 파일을로드하는 데 문제가 있습니다. 파일 이름이 고정되어 있지 않으며 파일 이름이 여러 번 나타납니다. 파일이 디렉토리 안에 저장되어 있는지 확인할 수 있으므로 문제가되지 않아야합니다. 나는 그것이 디렉토리 문서/Filename.db 내부 검색 할 - 그것은 단지 문서/내부 검색 있기 때문에

      나는, 내가 NSMetadataQuery에 문제를 아래로 추적 것 같아요. 정확한 경로에 대한 쿼리 serachScope 설정 시도했지만 결과를 반환하려면 검색 NSMetadataQueryUbiquityContainerDocumentsScope 사용해야 할 것 같습니다.

      - (NSMetadataQuery *)documentQuery 
      { 
      NSMetadataQuery *query = [[NSMetadataQuery alloc] init]; 
      
      NSString *appending = [NSString stringWithFormat:@"Documents/%@.db/", currentDirectory]; // Directory name 
      NSURL *documentPath = [[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent:appending]; 
      NSLog(@"Document Path: %@", documentPath); 
      
      if (query) { 
      
          [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; 
      
          NSString *filePattern = [NSString stringWithFormat:@"*.%@", STACK_EXTENSION]; 
          [query setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE %@", NSMetadataItemFSNameKey, filePattern]]; 
      
      } 
      
      return query; 
      
      } 
      
      - (void)processiCloudFiles:(NSNotification *)notification 
      { 
      [_query disableUpdates]; 
      [_iCloudURLs removeAllObjects]; 
      
      NSArray *queryResults = [_query results]; 
      for (NSMetadataItem *result in queryResults) { 
      
          NSURL *fileURL = [result valueForAttribute:NSMetadataItemURLKey]; 
      
          NSLog(@"---- FileURL: %@", fileURL); 
      
          NSNumber *aBool = nil; 
      
          [fileURL getResourceValue:&aBool forKey:NSURLIsHiddenKey error:nil]; 
          if (aBool && ![aBool boolValue]) { 
           NSLog(@"Adding following Stack: %@", fileURL); 
           [_iCloudURLs addObject:fileURL]; 
      
          } 
      
      } 
      
      NSLog(@"Found %d iCloud files", _iCloudURLs.count); 
      NSLog(@"iCloud URLs: %@", _iCloudURLs); 
      
      ... 
      
      } 
      

    답변

    0

    나는 당신의 디렉토리가 .DB 확장명이 내가 당신 으론의 전체 의미를 이해하지 못하는 이유를 잘 모르겠지만, 내가 iCloud에 저장을위한 편재 컨테이너에 하위 디렉토리를 사용하는 방법에 대해 물었다 때 나는 말을 들었다 내가 믿는 누군가는 하위 디렉토리를 추가 할 수있는 애플 엔지니어 였지만 "디렉토리가 없어야한다."라는 이름으로 또는 패키지로 취급되어 슬프게도 종료 될 수 있습니다. 또한 .nosync 항목을 컨테이너의 최상위 레벨. " 그는 또한 "설정은 문서를 평면 하이라이트로 표시하며 (예 : 디렉토리가 아닌 파일과 패키지 만 표시) 다른 UI 영역도 시각적으로 하위 디렉토리를 무시할 수 있습니다."

    디렉토리의 마스터 테이블에서 선택된 하위 디렉토리에있는 파일의 세부 테이블을 가지기 위해 쿼리의 모든 항목을 반복하고 URL에 하위 디렉토리가있는 항목 만 찾는 방법을 사용했습니다.

    관련 문제