我想将图像文件保存到组容器中,以便与 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();
如何实现这一点?
最佳答案
我从未见过任何人通过获取路径并尝试从 C# 写入来实现此目的。另外,我试过这个但也失败了。我猜你不能从 C# 中做到这一点。
我发现实现此目的的唯一方法是将写入功能移至插件。使用 Object-C 编写一个写入该目录的函数。此 Object-C 函数应采用两个参数:数据 (byte[]
) 和文件名 (string
)。然后,您可以从 C# 调用此函数,并将要保存的数据和文件名传递给 Object-C 插件。
关于ios - 无法使用 unity ios 将文件保存到 AppGroup 的共享容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46066767/