2011-10-24 11 views
6

मैं उपयोगकर्ता या ऐप द्वारा बनाई गई सभी निर्देशिकाओं की सूची में पढ़ना चाहूंगा जो iCloud की मोबाइल दस्तावेज़ निर्देशिका में है (जिसे शेर में ~/लाइब्रेरी में मिला है)/मोबाइल दस्तावेज़)। यहाँ कैसे इस निर्देशिका की तरह लग सकता है की एक उदाहरण है:iCloud: उपयोगकर्ता द्वारा बनाए गए निर्देशिकाओं में पढ़ने के लिए

iCloud's Mobile Documents

मैं निम्नलिखित कोड की कोशिश की, लेकिन क्वेरी मैं चलाने मेरी फ़ोल्डर (NSPredicate predicateWithFormat:@"%K.pathExtension = ''", NSMetadataItemFSNameKey का प्रयोग करके) का प्रतिनिधित्व करने के लिए किसी भी वस्तुओं शामिल नहीं होंगे। अगर मैं txt फ़ाइलों के लिए एक क्वेरी चलाता हूं (@"%K ENDSWITH '.txt'", NSMetadataItemFSNameKey का उपयोग करके), मुझे क्रमशः txt फ़ाइलों के लिए 5 ऑब्जेक्ट लौटाए जाएंगे। इस प्रकार txt फ़ाइलों की तलाश में काम करता है, लेकिन निर्देशिकाओं के लिए नहीं। docs के माध्यम से पढ़ते हुए, मैंने देखा कि ऐप्पल निर्देशिकाओं के बजाय NSFileWrapper (फ़ाइल पैकेज) का उपयोग करने का सुझाव देता है। क्या iCloud उपयोगकर्ता या ऐप द्वारा बनाई गई निर्देशिकाओं को संभालने/पहचानने में सक्षम नहीं है?

-(void)loadDocument { 

    NSMetadataQuery *query = [[NSMetadataQuery alloc] init]; 
    _query = query; 
    //Search all files in the Documents directories of the application’s iCloud container directories: 
    [query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; 

    NSPredicate *pred = [NSPredicate predicateWithFormat:@"%K.pathExtension = ''", NSMetadataItemFSNameKey]; 

    [query setPredicate:pred]; 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidFinishGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:query]; 
    [query startQuery]; 
} 

- (void)queryDidFinishGathering:(NSNotification *)notification { 

    NSMetadataQuery *query = [notification object]; 
    [query disableUpdates]; // You should invoke this method before iterating over query results that could change due to live updates. 
    [query stopQuery]; // You would call this function to stop a query that is generating too many results to be useful but still want to access the available results. 

    [self loadData:query]; 

    [[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:query]; 
    _query = nil; // we're done with it 
} 


- (void)loadData:(NSMetadataQuery *)query { 

    NSLog(@"Query count %i", [query resultCount]); 

    for (int i=0; i < [query resultCount]; i++) { 
     NSMetadataItem *item = [query resultAtIndex:i]; 
     NSURL *url = [item valueForAttribute:NSMetadataItemURLKey]; 
     NSLog(@"%i.URL: %@", i, url); 
    } 

} 

उत्तर

0

मैं "संग्रहण प्रबंधित करें" मैक ओएस एक्स शेर में iClouds सेटिंग्स में पर एक नज़र था:

यहाँ मेरी कोड है। जब मैं अपने एप्लिकेशन पर क्लिक करता हूं, तो यह केवल अलग-अलग txt फ़ाइलों (साथ ही विरोधाभासी संस्करण) और कोई निर्देशिका नहीं दिखाएगा। इसलिए मुझे यह मानना ​​है कि आप केवल रैपर/फ़ाइल पैकेज के साथ काम कर सकते हैं लेकिन निर्देशिकाओं के साथ नहीं।

+0

क्या आपने कभी यह काम किया है? इसके लायक होने के लिए, माउंटेन शेर उपयोगकर्ता ऐप के अंदर ओपन पैनल से फ़ोल्डर्स बनाने में सक्षम हैं। क्या आपने वहां 'NSMetadataQuery' एपीआई की कोशिश की है? इससे हमें संकेत मिलता है कि यह आईओएस में कैसे बदल रहा है ... – nacho4d

+0

@ nacho4d no, अंत में मैं फ़ोल्डर के साथ नहीं गया, क्षमा करें। जैसा कि आप कहते हैं, यह एम शेर के साथ बदल सकता है। अगर आपको कोई रास्ता मिल जाए तो मुझे पोस्ट रखें। –

+2

सिर्फ रिकॉर्ड के लिए (क्योंकि मुझे लगता है कि आपने पहले ही देखा है) मैंने यहां एक कार्य-पोस्ट पोस्ट किया है: http://stackoverflow.com/questions/7873974/returning-a-list-of-directories-with-nsmetadataquery-and-nspredicate/10510752 # 10510752 – nacho4d

संबंधित मुद्दे