Questions tagged [nsmetadataquery]

The NSMetadataQuery class encapsulates the functionality provided by the MDQuery opaque type for querying the Spotlight metadata.

The NSMetadataQuery class encapsulates the functionality provided by the MDQuery opaque type for querying the Spotlight metadata.

NSMetadataQuery objects provide metadata query results in several ways:

As individual attribute values for requested attributes. As value lists that contain the distinct values for given attributes in the query results. A result array proxy, containing all the query results. This is suitable for use with Cocoa bindings. As a hierarchical collection of results, grouping together items with the same values for specified grouping attributes. This is also suitable for use with Cocoa bindings. Queries have two phases: the initial gathering phase that collects all currently matching results and a second live-update phase.

By default the receiver has no limitation on its search scope. Use setSearchScopes: to customize.

By default, notification of updated results occurs at 1.0 seconds. Use setNotificationBatchingInterval: to customize.

You must set a predicate with the setPredicate: method before starting a query.

Reference: http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSMetadataQuery_Class/Reference/Reference.html

74 questions
3
votes
2 answers

Access metadata of a single file

Is there a way to programmatically access metadata of a single file on MacOS? I know Apple provides NSMetadataQuery, but it seems it only allows to search in particular folders for files matching some parameters. Actually I'd prefer not to search…
Manlio
  • 10,768
  • 9
  • 50
  • 79
3
votes
1 answer

Should I use the FileManager or NSMetadataQuery to retrieve filenames in iCloud, by an IOS/Swift app?

I see people are using the FileManager and NSMetadataQuery to retrieve filenames in iCloud, when programming an IOS/Swift app. Which is better, and safer ? It seems Apple wants you to use NSMetadataQuery, but the advantage for the FileManager, is…
nitin67
  • 83
  • 5
3
votes
1 answer

Error when performing a `NSMetadataQuery` in iCloud Drive

I get the following error when performing a NSMetadataQuery in iCloud Drive: [ERROR] cannot query iCloud Drive items: Error Domain=BRCloudDocsErrorDomain Code=16 "Sync is restricted for this client" UserInfo={NSDescription=Sync is restricted for…
Qbyte
  • 12,753
  • 4
  • 41
  • 57
3
votes
0 answers

NSMetadataQuery not triggering in Sandbox on macOS 10.13

I have been using NSMetaDataQuery to know when user takes a screenshot in a sandbox on macOS prior to 10.13 and it was working fine. But on 10.13 i only get notified when i start NSMetaDataQuery, and on updates i am not receiving any notification.…
3
votes
3 answers

NSMetaDataQuery does not complete

I’m trying to explore the files available to my app in iCloud using NSMetaDataQuery. I’m able to start the query, but it never finishes. Here’s my code. func report1() { let filemgr = FileManager.default let url =…
Jerry Agin
  • 629
  • 1
  • 5
  • 15
3
votes
2 answers

iCloud NSMetadataQuery and updates (NSMetadataQueryUpdateChangedItemsKey)

I am monitoring my iCloud sandbox (iOS) using an NSMetaDataQuery are recommended - and all is working well. I'm attempting to use the NSMetadataQueryUpdateChangedItemsKey in the NSMetadataQueryDidUpdateNotification in order to efficiently update my…
Scotty
  • 2,019
  • 1
  • 20
  • 31
3
votes
1 answer

Showing progress percentage while downloading a file from iCloud?

I'd like to show a progress bar while a UIDocument is being downloaded from iCloud. I tried keeping a reference to the NSMetadataItem from the query asking it for its attributes every second, but the key NSMetadataUbiquitousItemPercentDownloadedKey…
Mark
  • 6,647
  • 1
  • 45
  • 88
3
votes
0 answers

How to open a UIDocument after UIDocumentStateSavingError exists?

In my iCloud-based app, I noticed that if a crash were to occur while a UIDocument is open (and has not yet been closed), the status of the document sometimes becomes UIDocumentStateSavingError and it never opens successfully again. When I run…
Anton
  • 3,998
  • 25
  • 40
3
votes
1 answer

Setting batch parameters with NSMetadataQuery or MDQuery

It would be helpful if someone shares how batching a query is done using - - (void)setNotificationBatchingInterval:(NSTimeInterval)timeInterval when used with NSMetadataQuery or by using void MDQuerySetBatchingParameters ( MDQueryRef query, …
Shashank
  • 1,743
  • 1
  • 14
  • 20
3
votes
1 answer

Two iCloud devices get different results with NSMetaDataQuery

I'm using iCloud to store small audio files with a simple UIDocument class. Running iOS 5.1 on an iPhone 4s and an iPad 1. The iPad is communicating properly with the iCloud container. As I create documents, I see them pop into the iCloud store…
bgolson
  • 3,460
  • 5
  • 24
  • 41
2
votes
0 answers

iOS 14 NSMetadataQuery not updating; no notifications are sent, works on iOS13

I am using NSMetadataQuery to query a file on iCloud in an ubiquitous container. The code works as expected on iOS13.7, but it does NOT work on iOS14. On iOS 14 no notifications are sent to the app. Is this a known bug or an implementation issue…
Chris
  • 1,231
  • 2
  • 10
  • 20
2
votes
1 answer

How can I improve searching an iCloud Drive folder using NSMetadataQuery?

I'm trying to list the contents of a specific folder in iCloud Drive using NSMetadataQuery: let query = NSMetadataQuery() func listAllItemsInTheTestFolder() { guard let container = FileManager.default.url(forUbiquityContainerIdentifier:…
Syzygy
  • 123
  • 2
  • 9
2
votes
0 answers

NSMetadataQuery gets multiple (identical) DidUpdateNotification

I'm working on verifying an app works on iOS 11. On iOS 10, I start an NSMetadataQuery on the scope NSMetadataQueryUbiquitousDocumentsScope, and I get exactly one NSMetadataQueryDidFinishGatheringNotification. And that's it. That's the only…
randallmeadows
  • 833
  • 1
  • 10
  • 19
2
votes
0 answers

How to track down an iCloud upload properly?

I am trying to integrate iCloud usage in my app. I did understand how the process works and its basis. I was already able to upload content to iCloud but I need to track down the uploading progress in order to improve the Ux that I am providing to…
Tiago Pereira
  • 592
  • 1
  • 4
  • 19
2
votes
1 answer

Not able to get results for spotlight search for user tags with NSMetadataquery and kMDItemUserTags

I am at my wits end after trying to add a routine to my controller to search the user's computer for user files with specified user (Mavericks+) tags. I am running into a block where the search will start, but no results are returned and the…
TRQK
  • 35
  • 6