简体   繁体   English

CodenameOne - 库文件夹的 iOS 上的文件系统访问问题

[英]CodenameOne - filesystem access problems on iOS for Library folder

My CodenameOne app is being tested on the iOS simulator (iPad 8th iOS 14).我的 CodenameOne 应用程序正在 iOS 模拟器(iPad 8th iOS 14)上进行测试。

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.它适用于 CN 模拟器(写入 .cn1/ 文件夹内),但在 iOS 上捕获了异常。 The Library folder is of paramount importance on iOS. Library 文件夹对 iOS 至关重要。

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.我的应用程序的 CN 版本必须将这些私有文件写入与 swift 版本相同的位置,即库。

There is string manipulation, and no extra '/' are added, the file path seems legit.有字符串操作,并且没有添加额外的“/”,文件路径似乎合法。

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被转换并且 getRootPath() 方法返回

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:此外,在尝试写入后的某个时间点,我在控制台 output 中看到了我认为相关的内容:

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?和我的问题有关吗?

Is CN filesystem access broken or flawed? CN 文件系统访问是否损坏或有缺陷?

I know io access permissions are automatically created by the CN compiler, but are they working?我知道 io 访问权限是由 CN 编译器自动创建的,但是它们有效吗?

So how to fix my issue about the Library folder?那么如何解决我关于 Library 文件夹的问题呢?

The cn1storage printout just means the storage directory already exists. cn1storage打印输出只是意味着存储目录已经存在。

The way to get the library path is this: Getting an iOS application's "~/Library" path reliably获取库路径的方法是这样的: Getting an iOS application's "~/Library" path可靠

You need to use that approach.你需要使用这种方法。 I think your assumption that Document and Library reside under the exact same hierarchy is just incorrect.我认为您认为文档和库位于完全相同的层次结构下的假设是不正确的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM