Home > Blockchain >  How can I allow permissions for my Kivy app to access text files when running on an iOS device?
How can I allow permissions for my Kivy app to access text files when running on an iOS device?

Time:10-12

I have made a weather app with Python and Kivy for iOS and finally built it and got it running on the Xcode simulator. I wrote the program on Windows 10 but have been compiling it on Mac. I am able to build it on my iOS devices but when I run the apps functions, I seem to get permissionerror: [errno 1] operation not permitted: when my main.py tries to WRITE to .txt files. The .txt files that it is needing to reference are in the same working directory as all the other files eg. main.kv, firebase.py etc etc. so I'm not too sure what is happening here.

I have tried cleaning the build and deleting derived data and starting the build fresh. In the finder files, I have changed the permissions to allow "read and write" permissions on every file related to the app. The signing and capabilities are in my name and I have "Trusted" this through my devices.

Also, when I try any firebase authenticating on my actual device, the app crashes and exits, but on the simulator it works just fine. On my iPhone/iPad I can update the realtime database like normal, it's just breaking when it comes to authentication on firebase. I am guessing it's because it WRITES to "refresh_token.txt" file that is read when authentication occurs.

How can I allow the permissions for this on my iOS devices?? Is there a way to allow writing to files on iOS?

I am very new to using Mac/Xcode/Kivy so please be kind to me. I would appreciate any help here. Thank you very much.

Heres a screenshot of the xcode bundles. The text files are namely:

"alternate_figs.txt"

"briefing_results_1.txt"

"briefing_results_2.txt"

"refresh_token.txt"

I haven noticed that in this side window that they don't display the ".txt" part of the label. Does this have something to do with it?

enter image description here

CodePudding user response:

After much research I found out I wasn't allowed to write the the root folder of an iOS app and that it could only be written in a specific directory called user_data_dir. What I did in my program was just prepend all of my write file commands with self.user_data_dir .

So what was open("briefing_results_1.txt", "w") before is now just open(self.user_data_dir "briefing_results_1.txt", "w"). That solved everything.

  • Related