我正在使用Unity 5.6和Xcode 8.3.3,编译服务器可以成功导出'.ipa'文件,但应用程序无法访问文档文件夹。
Sep 25 11:09:56 padding-0 kernel[0] <Notice>: Sandbox: shiphunter(583) deny(1) file-write-create /Documents
Sep 25 11:09:56 padding-0 kernel[0] <Notice>: Sandbox: shiphunter(583) deny(1) file-write-create /Documents
Sep 25 11:09:56 padding-0 kernel[0] <Notice>: Sandbox: shiphunter(583) deny(1) file-write-create /Documents
Sep 25 11:09:56 padding-0 kernel[0] <Notice>: Sandbox: shiphunter(583) deny(1) file-write-create /Documents
我用来复制和写作的路径:
public static string ConfigPath
{
get
{
// the raw file path
return Path.Combine(Application.streamingAssetsPath, "Config");
}
}
public static string RESOURCE_FILE_PATH
{
get { return Path.Combine(Application.persistentDataPath, "res"); }
}
代码访问并在文档文件夹中创建新文件如下,可能步骤2或3导致此问题,我猜。
// 1. copy the raw data into bytes array
var bytes = new byte[0];
var dbpath = Path.Combine(Util.ConfigPath, "warship.sqlite3");
try
{
using (var fs = new FileStream(dbpath, FileMode.Open, FileAccess.Read, FileShare.Read))
{
bytes = new byte[fs.Length];
fs.Read(bytes, 0, (int) fs.Length);
}
}
catch (Exception e)
{
Debug.LogError(e);
}
// 2. create the res folder under documents if not exists
if (!Directory.Exists(RESOURCE_FILE_PATH))
{
Directory.CreateDirectory(RESOURCE_FILE_PATH);
}
// 3. write the bytes data into documents res foloder
var filename = Path.Combine(RESOURCE_FILE_PATH, "warship.sqlite3");
try
{
var fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
if (fs == null)
{
Debug.LogError("file stream is null:" + filename);
}
else
{
fs.Write(bytes, 0, bytes.Length);
fs.Close();
}
}
catch (Exception e)
{
Debug.LogError(e + ":" + e.StackTrace);
}