How to disable Documents folder protection?
The easy way is to turn off sandboxing for the app, in Xcode project settings under "capabilities". You might not want that though.

Otherwise you probably need a security-scoped bookmark to the directory. When you get access, create a bookmark from the directory URL using bookmarkData(options:includingResourceValuesForKeys:relativeTo:). Make sure to use .withSecurityScope in the options argument. Save that to user defaults. Then when you want to use the directory,


Read the bookmark from user defaults
Initialize the URL using init(resolvingBookmarkData:options:relativeTo:bookmarkDataIsStale:) with options of [.withSecurityScope, .withoutUI].
Call .startAccessingSecurityScopedResource() before trying to use the URL.
Call .stopAccessingSecurityScopedResource() when you're done with the URL.