4 Replies
      Latest reply on Dec 10, 2019 12:47 AM by eskimo
      zulfishah Level 1 Level 1 (10 points)

        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];
        
        • Re: NSMetadataQuery not working in Catalina
          eskimo Apple Staff Apple Staff (12,705 points)

          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"

            • Re: NSMetadataQuery not working in Catalina
              zulfishah Level 1 Level 1 (10 points)

              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).