iOS file write/create denied

642 views
Skip to first unread message

Albert Saiz

unread,
Mar 29, 2019, 1:16:42 PM3/29/19
to Kivy users support
Hello everyone, I made a kivy app for iOS. Everything works fine on the simulator but when I try it on a real device the App just crashes at launch. 
In the log I could see the following:
 Mar 29 17:34:44 iPhone-de-albert kernel(Sandbox)[0] <Error>: Sandbox: anoiaverda(2066) deny(1) file-write-create /private/var/containers/Bundle/Application/FD573B2C-901C-408C-B2F4-5CE40F43E38D/anoiaverda.app/YourApp/actual.dat
 Mar 29 17:34:44 iPhone-de-albert anoiaverda[2066] <Notice>: Application quit abnormally!
 Mar 29 17:34:44 iPhone-de-albert anoiaverda[2066] <Notice>: Leaving

As far as I know this is telling me that I don't have the permission to write or create files, in this case it is trying to create 'actual.dat'. 
Searching in google, I've seen there are some permissions like com.apple.private.security.no-container but I don't know where to find them and what permissions do I need.  Anyone more experienced with Xcode/iOS apps could help me? Thanks!

Michael Kramer

unread,
Mar 29, 2019, 3:13:43 PM3/29/19
to Kivy users support

On iOS you cannot write to the same folder where the app bundle is (where is also where your compiled python code eds up.) 

For file creating and writing on iOS it has to go to the apps 'Documents' folder, and the path to this looks something like:  /var/mobile/Containers/Data/Application/<BundleId>/Documents  - but the bunlde id that is used for the Documents folder is different than the one used for the actual application bundle.....

In my case I am getting this location of the apps Documents by calling into obj via pyobjus and using: 

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];

Then you can write anything you want to the documents directory.

It may be that Kivy already has this information floating around somewhere so there might be an easier way than having to go over the pyobjus border, if so then that would be easier, but at least the code above will get the info via objc if not.

And note that if you enable shared files in the xcode project you can access any files that python writes to the Documents directory via iTunes - just go to the file sharing tab when the phone is connected and you can drag and drop files from your kivy app.

hope this helps....



--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To post to this group, send email to kivy-...@googlegroups.com.
Visit this group at https://groups.google.com/group/kivy-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/7f7664f2-3a9e-49a0-8d4b-c3024dd49161%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Albert Saiz

unread,
Mar 29, 2019, 4:39:46 PM3/29/19
to Kivy users support
Thanks! This helps a lot

Albert Saiz

unread,
Mar 31, 2019, 4:06:38 PM3/31/19
to Kivy users support
I came up with an easier solution than using pyobjus. If you use App.get_running_app().user_data_dir and join it with the file you want to use, you can write, create and read without problems. Example:
appdir=App.get_running_app()
doc
=join(doc,'example.txt')
open
(doc,'w')#Nowyou can open it  in  any mode

The only problem is that this solution may not work depending on where you call it as some objects don't have this attribute. if you do some workarround and tricky stuff you can get it working anywhere you call it.
In general, there aren't any problems if you call it in parts of your code that are executed while the app is running.
Reply all
Reply to author
Forward
0 new messages