ios - 无法使用 unity ios 将文件保存到 AppGroup 的共享容器

标签 ios unity-game-engine 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(); 

如何实现这一点?

最佳答案

我从未见过任何人通过获取路径并尝试从 C# 写入来实现此目的。另外,我试过这个但也失败了。我猜你不能从 C# 中做到这一点。

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

关于ios - 无法使用 unity ios 将文件保存到 AppGroup 的共享容器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46066767/

相关文章:

ios - 除非选择为目标,否则框架中的 Xcode 警告不会显示在项目导航器中

ios - Obj-C - 如果 NSMutableArray 多次包含相同的字段,则从 TableView 中删除单元格

iphone - 如何在 touchesBegan、touchesEnded 中实现 Touch Up Inside

android - Unity 的第一个版本已调试并成功上传到 Play 商店。第二版给出了错误。为什么?

ios - iMessage 扩展不会在设备上运行

ios - 收藏 View 中的标题不会显示?曾经工作?

iOS 允许用户信任某些证书?

unity-game-engine - Unity3D 尝试理解 Monoscript

c# - OnControllerColliderHit 触发次数过多

ios - 如何本地化 iMessage 贴纸?