NSMetadataQuery not working in Catalina

Hi,

I have been NSMetadataQuery to monitor the Documents folder of my app to pick up new files that were added. This stopped working in Catalina. Is this a documented issue or change in functionality? Is there any new security permission or privacy thing that I have to enable in my app to continue monitoring the local Documents folder from my own app?


This is the code I was using the setup folder monitoring (which works fine in Mojave ... but not in Catalina):

self.metadataQuery = [[NSMetadataQuery alloc] init];
[self.metadataQuery setSearchScopes:@[dropLocation.path]];
[self.metadataQuery setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE '*.eml'", NSMetadataItemFSNameKey]];
    
[[NSNotificationCenter defaultCenter] addObserverForName:NSMetadataQueryDidFinishGatheringNotification
                                                      object:self.metadataQuery
                                                       queue:nil
                                                  usingBlock:^(NSNotification *note) {
                                                      // do nothing ... not sure why it's required
                                                      NSLog(@"NSMetadataQueryDidFinishGatheringNotification called");
                                                  }];
    
[[NSNotificationCenter defaultCenter] addObserverForName:NSMetadataQueryDidUpdateNotification
                                                      object:self.metadataQuery
                                                       queue:nil
                                                  usingBlock:^(NSNotification *note) {
                                                      NSLog(@"NSMetadataQueryDidUpdateNotification called");
                                                      [self processResultsForQueryWithStartDate: date];
                                                  }];
    
[self.metadataQuery startQuery];

Replies

Is there any new security permission or privacy thing that I have to enable in my app to continue monitoring the local Documents folder from my own app?

10.15 does have an important change with regards the Documents directory. WWDC 2019 Session 701 Advances in macOS Security has the details.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

To be clear, the folder is the 'documents' folder from my own app's container:

/Users/<username>/Library/Containers/com.myapp.macapp/Data/Documents


Is this folder also protected now?

I saw the linked video, but it wasn't clear what was new in this regard, or what I would need to do to fix this. Again, I'm using NSMetadataQuery to monitor this folder for changes. When building my app in Xcode, in 'Signing & Capabilities', I already have the "User Selected Files" permission selected with Read/Write, though not the others (Downloads, Pictures, Music, Movies).

I've also tried giving my app "Full Disk Access" permissions, from System Preferences, but doesn't seem to help.

To be clear, the folder is the 'documents' folder from my own app's container:

Ah, sorry, I missed that subtlety.

Is this folder also protected now?

No. The change I’m referring to only affects

~/Documents/
.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
I have exactly the same problem, did you found a solution?