这是我的代码:我创建了一个灵活的移动应用程序,我想在其中将文件以pdf格式保存在iPad/iPhone(任何IOS设备)中但是在保存该文件时,它的贯穿#2038错误。这是我的代码。
var file:File = File.desktopDirectory.resolvePath("indicators.pdf");
if (file.exists)
file.deleteFile(); //delete it if exists
//create a file stream to be able to write the content of the file
var fileStream:FileStream = new FileStream();
var popUpPage:AlertPage = new AlertPage();
try
{
//open the file stream and set for Write
fileStream.open(file, FileMode.WRITE);
//writes the bytes
fileStream.writeBytes(pdfBytes, 0, pdfBytes.length);
//close the stream
fileStream.close();
PopUpManager.addPopUp(popUpPage,this,true);
popUpPage.lblAlert.text = "indicator saved in pdf format = "+ file.nativePath;
PopUpManager.centerPopUp(popUpPage);
this.visible = false;
}
catch(err :Error)
{
PopUpManager.addPopUp(popUpPage,this,true);
popUpPage.lblAlert.text = err.message + " "+ file.nativePath;
PopUpManager.centerPopUp(popUpPage);
}
您无法在任何移动设备上保存到desktopDirectory
。您的应用程序仅允许保存到 applicationStorageDirectory
。由于这个原因,您那里拥有的东西每次都会出错。
作为一个简单的技巧,您应该这样做以允许两者。
private const isDesktop:Boolean = false;
private var baseDirectory:File = ( isDesktop ) ? File.desktopDirectory:File.applicationStorageDirectory;
//and to declare a file, do this
private var pdf:File = this.baseDirectory.resolvePath( 'blah.pdf' );
因此,您切换 isDesktop
属性以选择要使用的属性,并相应地声明baseDirectory
。然后,您只需每次都从baseDirectory
解析路径,而不是执行硬编码applicationStorageDirectory
或desktopDirectory
。
从长远来看,此方法对于调试要灵活得多。
不确定权限如何在Android上工作,但是在我们的桌面环境(Flex-Desktop应用程序)中,我们能够通过修复文件夹权限(授予用户读取-写入-修改权限)来消除错误