My app needs access to certain folders and the contents of them (that the user picks) outside of the sandbox. I have that working well and all, however when the app restarts, I can still see what’s inside the folder, but I can’t read the files inside the folder.
I’m getting access to the folder through a simple NSOpenPanel, which like I said, works and gives me access to all files and subfolders until the app is restarted.
Is there any way I can make it so the NSOpenPanel grants me permanent access to the files?
The permission has been revert back to its original condition when restarted , you might want to check again the implementation of the folder access to be granted automatically
Related
I'm asking this question because I did not find any answer, and I'm starting to believe that it's not possible, due to security reasons. But who knows?
In my app, I simply let the user save a PDF file using UIActivityViewController. The user then chooses Save to file, then selects iCloud Drive.
Now, users ask me to be able to select a default location once and for all.
Is it possible? This location would of course be outside the app container, then I suppose iOS won't grant access unless the user selected it itself.
Yes you can. Using UIDocumentPickerViewController you can ask for a directory, and you can save it in your app. This is explained in detail in Providing Access to Directories. iOS 13 and later.
See also What's New in File Management and Quick Look for sample code saving a directory URL and then reusing it to set the base directory for a subsequent call to UIDocumentPickerViewController
I know about the path_provider package but it doesn't do what i want, or maybe I'm not just using it right. I read after so many trials and errors that the getApplicationDocumentsDirectory() returns a directory that is accessible only by the app itself, but what if i want to write to a phone's local document directory or so and be able to view the file in my file explorer later on?
If you want to save where the file explorer reaches, you must use the method getExternalStorageDirectory(). It only works in Android and you'll need READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE permissions.
Actually, you're able to find the files saved using getApplicationDocumentsDirectory() and getTemporaryDirectory() as well, but you'd need root access.
I accomplished writing an application code in Matlab. I create a .mat file and save data into it somewhere in the code. I converted it to a standalone application file.(exe) However, I don't want to give permission to the user to see and modify this .mat file because the application uses that file in the next executions. For this reason, I changed the permission settings by right clicking the folder and:
properties-Security-Advanced-Changed Permission
However, after changing the permission, the code cannot reach that file and fails while executing. How can I handle it?
To my opinion you are approaching this the wong way. To make that concept working, your application would require higher permissions than the user has, especially the user may not modify permissions. For the majority of self-administrated PCs this is impossible, because the primary user has full administrative rights, allowing to modify folder permissions.
For such cases the typical solution is encryption. Assume everyone can access your files, store only encrypted files to the hard drive.
i need to place a backup database in my iphone. so i want any place outside my app folder where i can place the backup database so that if due to any problem my app crashes the user has a copy of his data.
any other idea except of placing data on a remote server is acceptable.
Why does it need to be outside your app folder, you could just copy and rename your database file and keep it in your app folder. I'm not sure it's possible to write outside your app folder.
My iPhone app uses a small database to store its settings and saved files. How can I ensure that the default database, with its default settings, gets distributed to anyone who downloads it along with the application files?
EDIT Sorry, I was in a rush when I posted this. I forgot to mention that the database needs to end up in the 'Documents' folder of the application so that it can be backed up at a later date by the user.
-Ash
Put it in "Resources". Then on your first launch, you'll need to load that file out of your mainBundle and save it to the Documents directory. The file will "come with" the app, but it won't live in the right place to get caught by backup.
A side-effect is that restoring the app to factory settings is as easy as deleting that file. Next launch, you can see you don't have your file, and copy a fresh one out of your bundle.
You include it as a file in the Resources folder of your application.