CodenameOne app compatibility with iOS Library app folder

125 views
Skip to first unread message

P5music

unread,
Jan 4, 2021, 2:07:48 PM1/4/21
to CodenameOne Discussions
My CodenameOne app is intended for iOS, but I also created a native app with XCode.
The two apps should be compatible, in regard to data files in the app private folder.

At present stage the CodenameOne app writes data to the main private folder /
while the Swift app uses the following instructions, as suggested in the official guidelines, if I am not wrong:

 let dir = try! FileManager.default.url(for: .libraryDirectory, in: .userDomainMask, appropriateFor: nil, create: true);
let fileUrl = dir.appendingPathComponent(fileName).appendingPathExtension("json");

I do not think that the "Library" is the main private folder, so I need to understand if it is necessary for the CodenameOne app to create a subfolder. And what should be the path.

Thanks in advance

Shai Almog

unread,
Jan 4, 2021, 10:18:47 PM1/4/21
to CodenameOne Discussions
The first FileSystemStorage root maps to the "Documents" folder. The second maps to caches and the third root maps to the resources dir.

P5music

unread,
Jan 5, 2021, 3:59:09 AM1/5/21
to CodenameOne Discussions
I am talking about Storage, not FileSystemStorage.
That is the app private folder, not the user data folder.
I think the iOS Library folder should be inside it.
Regards

Shai Almog

unread,
Jan 5, 2021, 10:16:04 PM1/5/21
to CodenameOne Discussions
Storage uses the documents folder on our iOS port. Not sure we have that path you're talking about. Most of that code is ~9 years old so I don't recall.

P5music

unread,
Jan 6, 2021, 4:11:48 AM1/6/21
to CodenameOne Discussions
Does the user see those files?

Shai Almog

unread,
Jan 6, 2021, 10:05:24 PM1/6/21
to CodenameOne Discussions
Not really but by hacking maybe.

P5music

unread,
Jan 7, 2021, 7:44:20 AM1/7/21
to CodenameOne Discussions
I found somewhere that the url is something like
file:///var/mobile/Containers/Data/Application/strangenumberslike...EF22-EB33-4B65-9772-67ED7870E3E9/Library/
where the numbers are ever changing ID for the app, do not care about it.

What can you say about pointing to that path in Codename?
Regards

Shai Almog

unread,
Jan 8, 2021, 3:08:25 AM1/8/21
to CodenameOne Discussions
We don't determine any paths. We ask the OS for the paths. The numbers are from iOS itself.

P5music

unread,
Jan 8, 2021, 3:58:38 AM1/8/21
to CodenameOne Discussions
I need to know if it is possible to access the Library directory. You said that the Document folder is used.
So is there no chance to have the Library path?
Regards

Shai Almog

unread,
Jan 9, 2021, 1:12:42 AM1/9/21
to CodenameOne Discussions
You can access everything via a native interface. If you have a specific path you can open it just fine with FileSystemStorage.

P5music

unread,
Jan 9, 2021, 4:07:28 AM1/9/21
to CodenameOne Discussions
1- Is that private internal app folder accessible (read/write) via FileSystemStorage?
2-Could the path be created by string concatenations? I mean, you wrote that the OS gives you that strange absolute path with ID, it could be used to just create the needed path. Is it contained in the Document complete path so to be taken from there with some substring method?
Thanks

Shai Almog

unread,
Jan 9, 2021, 9:51:23 PM1/9/21
to CodenameOne Discussions
1. Yes.
2. I guess you could but I never spent any time looking at the generated paths.

P5music

unread,
Jan 11, 2021, 1:20:23 PM1/11/21
to CodenameOne Discussions
My idea about paths seem to be right.
But I need to know what is the app private folder path in Android, so to create a fallback when I run/test on Android device/emulator.
I suppose it is not the real private app folder like it is in normal Android development. Is it?
Regards

Shai Almog

unread,
Jan 11, 2021, 9:39:35 PM1/11/21
to CodenameOne Discussions
Sorry. I'm not aware of any such path.

P5music

unread,
Jan 12, 2021, 3:22:21 AM1/12/21
to CodenameOne Discussions
I just need to  know the path of the corresponding directory in Android that the app sees as "/".
(in iOS you said it is the app folder Document)
Thanks

Shai Almog

unread,
Jan 12, 2021, 10:16:59 PM1/12/21
to CodenameOne Discussions
You mean the storage folder?
I have no idea where that is.

P5music

unread,
Jan 13, 2021, 3:48:53 AM1/13/21
to CodenameOne Discussions
Please tell me the Android method that is called, so at least I can assess what private/not private folder you picked up in this case.
Regards

P5music

unread,
Jan 13, 2021, 1:41:45 PM1/13/21
to CodenameOne Discussions
I created this method:

public static String getRootPath()
{
String os=Display.getInstance().getPlatformName();

if (os.toLowerCase().contains("ios")) {
String documentsRoot=FileSystemStorage.getInstance().getRoots()[0];
int pos=documentsRoot.lastIndexOf("Documents");
String libraryRoot=documentsRoot.substring(0,pos)+"Library";
return libraryRoot+"/";

}

return FileSystemStorage.getInstance().getRoots()[0]+"/";

}

This clearly has to be used with FileSystemStorage not Storage.
FileSystemStorage.getInstance().openOutputStream(getRootPath()+fileName+".ext");
So the result would be the same? That is, the private folder would be accessed and written even if it points to private Storage?

Regards

Shai Almog

unread,
Jan 13, 2021, 10:01:48 PM1/13/21
to CodenameOne Discussions
This wouldn't work. Android doesn't let you write to the root folder of the device. It strongly limits write access in the OS.
Reply all
Reply to author
Forward
0 new messages