无法使用unity

时间:2017-09-06 04:26:24

标签: ios unity3d imessage-extension

我想将图像文件保存到组容器以与iMessage扩展一起使用,作为Unity生成的标签,所以我写了一个ios插件来获取容器路径并将数据保存到相应的路径,我已成功得到

的路径
/private/var/mobile/Containers/Shared/AppGroup/1C848C27-6215-4C6F-98A9-E42E7794826D

但由于以下异常而无法保存:

    IsolatedStorageException: Could not find a part of the path "/private/var/mobile/Containers/Shared/AppGroup/1C848C27-6215-4C6F-98A9-E42E7794826D/Documents/0.jpg".
  at System.IO.FileStream..ctor (System.String path, FileMode mode, FileAccess access, FileShare share, Int32 bufferSize, Boolean anonymous, FileOptions options) [0x00000] in <filename unknown>:0 
  at System.IO.File.Create (System.String path, Int32 bufferSize) [0x00000] in <filename unknown>:0 
  at TestSharedContainer.saveImageToFolder () [0x00000] in <filename unknown>:0 
  at TestSharedContainer.OnGUI () [0x00000] in <filename unknown>:0 

我使用c#

中的以下代码保存文件
string fs_share_path = containerPath + "/0.jpg";
Debug.Log("writing :" + fs_share_path);
FileStream fs_share = File.Create(fs_share_path);
fs_share.Write(text.EncodeToJPG(), 0, text.EncodeToJPG().Length);
fs.Close(); 

如何使这项工作?

2 个答案:

答案 0 :(得分:1)

我从来没有见过任何一个通过获取路径并尝试从C#写入它的工作。此外,我试过这个但也失败了。我想你不能用C#来做。

我发现为此工作的唯一方法是将write函数移动到插件。使用Object-C编写写入该目录的函数。此Object-C函数应采用两个参数:数据(byte[])和文件名(string)。然后,您可以从C#调用此函数,并将数据传递给保存,并将文件名传递给Object-C插件。

答案 1 :(得分:0)

我注意到Unity的Application.persistentDataPath在iOS上返回了以/var/mobile/Containers/Data/Application/开头的路径。

我已尝试中断AppGroups的容器路径,使其以/var/mobile/Containers/Shared/AppGroup/开头,并使文件写入/读取工作从C#/ Unity端。