How does my iOS app get file write permission?

Hi!
I tested my app on an iPhone 8 simulator in Xcode without problems, but when I tried to run it on a physical iPhone 5s I get an error saying that I can't write a file. Why? Where do I change that?:

PermissionError: [Errno 1] Operation not permitted: 'geo-esp-train.cfg'
2021-02-28 23:09:59.085006+0100 geo-esp-training[457:91293] Application quit abnormally!
2021-02-28 23:09:59.294003+0100 geo-esp-training[457:91293] Leaving

Answered by HenrikRo in 666414022
Solved!

It turns out that the fact that Xcode and iOS and dlopen could not find a 'Foundation.framework' 'image' was not the real problem.
Python gave this error log:

Traceback (most recent call last):
File "/Users/henrik/geo-esp-training-ios/YourApp/main.py", line 252, in <module>
File "/Users/henrik/geo-esp-training-ios/YourApp/main.py", line 180, in __init__
PermissionError: [Errno 1] Operation not permitted: 'geo-esp-train.cfg'
2021-03-10 14:18:50.105679+0100 geo-esp-training[448:20514] Application quit abnormally!
2021-03-10 14:18:50.161136+0100 geo-esp-training[448:20514] Leaving

The solution was to actively specify in Python-Kivy that my data files have to be written to the app user data directory. This is how to do that:

Code Block
class RootLayout(FloatLayout): # This is the root widget of my Kivy app
def __init__(self, kwargs):
super().__init__(kwargs)
app = App.get_running_app()
print("app.directory = ", app.directory)
print("app.user_data_dir = ", app.user_data_dir)
global configfilename, user_data_dir_path
configfilename = os.path.join(app.user_data_dir, 'geo-esp-train.cfg')
user_data_dir_path = app.user_data_dir # Used for other data files.


Can you show your code causing the error?
It's Python. The error occurs in this file write operation statement (line 180):
Code Block
with open(configfilename, 'w') as config_file:
json.dump(self.config_data, config_file)

Here is the Traceback:

Traceback (most recent call last):
File "/Users/henrik/geo-esp-training-ios/YourApp/main.py", line 252, in <module>
File "/Users/henrik/geo-esp-training-ios/YourApp/main.py", line 180, in __init__
PermissionError: [Errno 1] Operation not permitted: 'geo-esp-train.cfg'
2021-02-28 23:09:59.085006+0100 geo-esp-training[457:91293] Application quit abnormally!
2021-02-28 23:09:59.294003+0100 geo-esp-training[457:91293] Leaving


What's configfilename?
That's a global string variable:

configfilename = 'geo-esp-train.cfg'

configfilename = 'geo-esp-train.cfg'

I do not have experience about writing apps in Python, but isn't that pointing some place where app cannot touch?
It's simply a filename. No path. In Android the OS automatically allocates a default folder for the app, where the file is automatically created. So I presumed that iOS works in a similar way?

In Android the OS automatically allocates a default folder for the app, where the file is automatically created. So I presumed that iOS works in a similar way?

It depends on the framework you are using.
OK. Interesting! Does that mean that this error is the result of the error I reported in another question, that has not yet been answered?:

https://developer.apple.com/forums/thread/675071 - Got dlopen error on Foundation: (...): image not found
PS: It's late night here in Europe, so I will go to bed now. :-)

Does that mean that this error is the result of the error I reported in another question, that has not yet been answered?

Not sure, but it may be a bug of the framework you are using. Better visit the supporting site of it, I believe it is not a framework of Apple's.
Sorry for not getting back earlier!
Someone suggested that I tried a newer iPhone, so I bought an iPhone 7. But that didn't help. I get exactly the same problem.
You say: "Visit the supporting site of that framework".
Would that be the github page for Python-Kivy-iOS - https://github.com/kivy/kivy-ios/ ?
I already tried posting an issue there, without any answers.... :-(
Please help. It's important that I get this app to run on iOS!

I already tried posting an issue there, without any answers.... :-( 

You have one option, give up using such an unreliable framework. Of course you may need to fully re-write your code...
You can wait here, very rare but there may be some people who would write some solution about non-Apple frameworks.

You can continue waiting for replies in this site until the moderator of this site closes this thread. Good luck.
Accepted Answer
Solved!

It turns out that the fact that Xcode and iOS and dlopen could not find a 'Foundation.framework' 'image' was not the real problem.
Python gave this error log:

Traceback (most recent call last):
File "/Users/henrik/geo-esp-training-ios/YourApp/main.py", line 252, in <module>
File "/Users/henrik/geo-esp-training-ios/YourApp/main.py", line 180, in __init__
PermissionError: [Errno 1] Operation not permitted: 'geo-esp-train.cfg'
2021-03-10 14:18:50.105679+0100 geo-esp-training[448:20514] Application quit abnormally!
2021-03-10 14:18:50.161136+0100 geo-esp-training[448:20514] Leaving

The solution was to actively specify in Python-Kivy that my data files have to be written to the app user data directory. This is how to do that:

Code Block
class RootLayout(FloatLayout): # This is the root widget of my Kivy app
def __init__(self, kwargs):
super().__init__(kwargs)
app = App.get_running_app()
print("app.directory = ", app.directory)
print("app.user_data_dir = ", app.user_data_dir)
global configfilename, user_data_dir_path
configfilename = os.path.join(app.user_data_dir, 'geo-esp-train.cfg')
user_data_dir_path = app.user_data_dir # Used for other data files.


How does my iOS app get file write permission?
 
 
Q