ios - 使用lua io.open在iOS上拒绝权限

标签 ios lua permission-denied

我在iOS上使用Lua,但在使用io.open(“filename.txt”,“w”)打开文件时遇到问题,始终收到“权限被拒绝”错误。
我知道Lua在读写时需要文件的整个路径,但是iOS等移动操作系统通过“沙盒”遮盖了文件系统。
我解决了吗?

注意:我没有使用Corona SDK。

最佳答案

只要您通过system.pathForFile("file.txt", directory_enum)获得文件路径,它们就将相对于正确的沙盒文件夹,其中directory_enumsystem.DocumentsDirectorysystem.ResourceDirectory等。

否则,即使我正在使用电晕,我也遇到了完全相同的“权限被拒绝”问题。因此,问题在于,在io.open调用返回错误之前,我有另一个io.open调用,该调用旨在读取相同的文件,但此后未关闭文件句柄。
因此,简单地说:

io.open(path, "r")
...
io.open(path, "w") --ERROR! this one returns a nil handle and a "permission denied"!

要解决此问题,请执行以下操作:
local fh = io.open(path, "r")
...
io.close(fh) --close the file after finishing with it
...
io.open(path, "w") --now the file is closed and can be opened again

关于ios - 使用lua io.open在iOS上拒绝权限,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23974056/

相关文章:

ios - 开始日期、结束日期以及在 ViewController 中向标签添加文本

Lua多参数入表深度

c - 数字在 Lua 和 C 中都表现得很奇怪

android - 写入 context.getFilesDir() 时为 "Permission denied"

ios - 表格 View 单元格仅在滚动关闭然后重新打开后才能正确屏蔽

iOS 'colorWithPatternImage' 在我的图片周围添加了 1 px 的边框?

iOS - 为 UITextField 实现一个类

lua - 尝试加载库;出现 "bad image"错误

python - "import babel.dates"让我的权限被拒绝

jquery - 权限被拒绝 - 在 jquery Horizo​​ntal Accordion 中打开 Vimeo