This cannot be done with code at runtime. There is a trick, but it can only be useful if you do not have a lot of data to exchange. Enable file sharing in plist. Then put all the files in the folder name, for example “Share”, and then set the switch to the user interface when the user turns off the switch, and then rename this folder like this “.Share”, then it will be hidden and no longer available for sharing .
Note: this trick is not a good way, but it works when you need it.
source share