My code works in Xcode simulator but it doesn't in iPhone

I have a very simple program, which works python kivy.

In that program I read and write json files.

Everything is fine with every simulator in Xcode Version 13.4.

However when I connect my Phone it can read the json file but can't write in it.

It says;

`File "/Users/batuhan/programs/kivy-ios/2800-ios/YourApp/main.py", line 429, in secom
PermissionError: [Errno 1] Operation not permitted: '/private/var/containers/Bundle/Application/C2508051-03DA-40EC-8587-A40D8B922055/2800.app/YourApp/savelist1.json'
2022-05-19 20:14:09.322995+0300 2800[3486:1776834] Application quit abnormally!
2022-05-19 20:14:09.416628+0300 2800[3486:1776834] Leaving`

As I understand so far it is all about build settings in Xcode.

Because as MacBook user I can write in that json file in simulator and everything works perfect.

I need to give permission to write json file for every user, staff or everyone.

I am just a beginner in Xcode, I think it is related with those settings;

The json file is in same directory with main.py

I don't think you can write there.

The Kivy App class has a method named get_application_config() (check the documentation) that gives you a writable directory, with the "appdir" keyword on iOS:

app.get_application_config('%(appdir)s')

I think mansourmoufid has the right answer but I just wanted to expand on it a bit.

You wrote:

It says;

[Errno 1] Operation not permitted: '/private/var/containers/Bundle/Application/C2508051-03DA-40EC-8587-A40D8B922055/2800.app/YourApp/savelist1.json'

Error 1 is EPERM, indicating that the file system operation was blocked by the sandbox. And look at the path in play: 2800.app/YourApp/savelist1.json. You’re trying to write a file within your app’s own bundle. This is not a good idea. To quote Embedding Nonstandard Code Structures in a Bundle:

A bundle is a read-only structure. All Apple platforms except the Mac enforce this requirement at runtime. On iOS, for example, any attempt to modify your app’s bundle at runtime will fail with an error. The Mac may or may not enforce this requirement at runtime, depending on the context, but modifying your app’s bundle isn’t supported because it breaks the seal on the app’s code signature.

Your app works on the simulator because an app in the simulator is kinda like a Mac app. As soon as you run it on the device it fails because the device enforces this restriction.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Dear @mansourmoufid and @eskimo, thank you very much for your support. I have read some documents and examples. However I couldn't construct the code.

There is a function that creates .ini file;

And when I call that function under mainwidget;

I print this directory;

But I think .json files are not in that directory. Also the directory seems wrong whatsoever. Normally main.py, kivy file and json files are located in same file. I simply can't load .json file to that directory. I am trying 2 ways. First one, I try to add them to created .ini file due to this explanation;

Second is add them to another .ini file and use that .ini file as directory.

But in both ways I have failed so far. I keep try and read and learn more about it.

If you have some comment about that I appreciate a lot.

My code works in Xcode simulator but it doesn't in iPhone
 
 
Q