问题描述
我正在 iOS 模拟器中测试 codenameone 应用。
该应用程序可以使用自定义扩展名管理文件,它可以通过“私人”文档文件夹导入/导出文件,该文件夹公开给“文件”应用程序和 iTunes。 此功能有效。文件路径类似于:
file:///Users/mac/Library/Developer/CoreSimulator/Devices/alphanumeric string here/data/Containers/Data/Application/another alphanumeric string here/Documents/filename.ext
现在,在应用程序的构建提示中有 plist 注入部分,它正确地包含了完整处理具有自定义扩展名的文件所需的所有标签。 此类文件可以在 Files 应用程序中选择,甚至可以从 OSX 主机系统中拖放。注入的部分取自使用 Xcode 本身创建的示例 Swift 应用程序(文档应用程序)。
这个不同的功能也适用于应用程序端,因为应用程序每次都被前景化并且传递了 AppArg 参数。
相关代码如下:
public void start()
{
...
...
String arg=display.getInstance().getProperty("AppArg",null);
if (arg!=null)
{
importArg(arg);
}
}
文件路径的格式相同,只是使用了 Documents/InBox 文件夹。 事实上,是 codenameone 系统在幕后工作来处理这个问题。
这是一个例子:
file:///Users/mac/Library/Developer/CoreSimulator/Devices/alphanumeric string here/data/Containers/Data/Application/another alphanumeric string here/Documents/InBox/filename.ext
ios.newStorageLocation=true
被使用,这使得
FileSystemStorage.getInstance().getRoots()[0]
像往常一样返回 Documents 路径。
但选择自定义文件时,或拖动/删除有一个“未找到文件:”日志中的错误,实际上似乎文件根本不会在收件箱子文件夹中复制。
相关代码如下:
public static String readTextFileFromUrl(String url) throws IOException {
try(InputStream is = FileSystemStorage.getInstance().openInputStream(url);)
{
return Util.readToString(is);
} catch(IOException err)
{
String error=err.getMessage();
System.out.println(error); //this is where the error is printed to console
}
return null;
}
(当用户从 Documents 文件夹导入文件时,此代码有效)
尝试从模拟器上的 iCloud 驱动器打开自定义文件时出现类似错误。
在这两种情况下,都传递了路径,但似乎没有有效地复制文件以供应用程序使用。
String documentsRoot=MyUtils.getDocumentPath();
com.codename1.io.File file=new File(documentsRoot+"InBox");
if (!file.exists())
{
file.mkdir();
System.out.println("created InBox "+file.getAbsolutePath());
}
通常不执行此代码,在控制台输出中找不到“已创建的收件箱...”。我认为收件箱子文件夹已经存在。
但有时当它被执行并且应用程序自己创建收件箱时,然后导入工作,文件被读取,并且收件箱文件列表显示其中的文件。
因此,CN1 可能错误地创建了该子文件夹(权限或其他),而如果应用程序创建了它,则它可用。
这是个问题吗?还是我做错了什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)