All paths in Codename One must be absolute paths not relative paths so ../
wouldn't be valid.
On Monday, May 10, 2021 at 9:09:55 AM UTC+3 P5music wrote:
> As you can see the method returns the correct value
> .../Library/
> and the file name is appended, so the final result is a valid file path,
> like
> .../Library/filename.ext
> Indeed you can see that the root path undergoes a string manipulation, so
> there are no extra '/'.
> Even if the root is like '.../Documents/', the string manipulation strips
> the entire final part before adding the replacement.
>
> So what's the problem? Maybe default FileSystem permissions in the XCode
> project are not working in OS14? Something else?
> Regards
> Il giorno lunedì 10 maggio 2021 alle 04:10:42 UTC+2 Shai Almog ha scritto:
>
>> By default we return directories with a / already there. It looks like
>> you're adding an extra / and iOS is very sensitive to those things.
>>
>> On Sunday, May 9, 2021 at 4:19:06 PM UTC+3 P5music wrote:
>>
>>> My app is being tested on the iOS simulator.
>>>
>>> It writes some files in the private folder by means of this method:
>>>
>>> public void writeFile() throws IOException {
>>> try(OutputStream os = FileSystemStorage.getInstance
>>> ().openOutputStream(Utils.getRootPath()+DATA_FILE);)
>>> {
>>> os.write(JSONText.getBytes("UTF-8"));
>>> os.flush();
>>> os.close();
>>> } catch(IOException err) {
>>> System.out.println("exception trying to write");
>>> }
>>> }
>>>
>>> It works on the CN simulator (writes inside the .cn1/ folder)
>>> but on iOS the exception is catched.
>>>
>>> Below is the method to get the root path
>>> public static String getRootPath()
>>> {
>>> String documentsRoot=FileSystemStorage.getInstance().getRoots()[0];
>>> String os=Display.getInstance().getPlatformName();
>>>
>>> if (os.toLowerCase().contains("ios")) {
>>>
>>> int pos=documentsRoot.lastIndexOf("Documents");
>>> if (pos==-1) return documentsRoot+"/";
>>> String libraryRoot=documentsRoot.substring(0,pos)+"Library";
>>> String result=libraryRoot+"/";
>>>
>>> return result;
>>> }
>>>
>>> The CN version of my app has to write those private files in the same
>>> location as the swift version, that is Library.
>>> So the string
>>>
>>> file:///Users/mac/Library/Developer/CoreSimulator/Devices/alphanumeric-string/data/Containers/Data/Application/another-alphanumeric-string/Documents/
>>> is transformed and
>>> the getRootPath() method returns
>>>
>>> file:///Users/mac/Library/Developer/CoreSimulator/Devices/alphanumeric-string/data/Containers/Data/Application/another-alphanumeric-string/Library/
>>> But there is exception.
>>>
>>> Furthermore, at some point after the writing attempt, I see in the
>>> console output something I think is relevant:
>>> Failed to create directory
>>> /Users/mac/Library/Developer/CoreSimulator/Devices/alphanumeric-string
>>> /data/Containers/Data/Application/another-alphanumeric-string
>>> /Documents/cn1storage/
>>>
>>> What is this? Is it related to my problem? How to fix it?
>>> Thanks in advance
>>>
>>
--
You received this message because you are subscribed to the Google Groups
"CodenameOne Discussions" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/codenameone-discussions/45fc77b6-f7f9-48ce-8f7b-6c1393e0faa4n%40googlegroups.com.