困っていること
Unity上で作成したアプリを、ビルドしてIOS端末でテストプレイをしてみたのですが、jsonファイを保存することができません。
環境
unity 2019.3.0f3
Xcode 11.2.1(11B53)
IOS 11.4.1
コード
C#
1static void SavePlayerDate(PlayerDate playerdate) 2 { 3 StreamWriter writer; 4 string jsonstr = JsonUtility.ToJson(playerdate); 5 writer = new StreamWriter(Application.streamingAssetsPath + "/playerdata.json", false); 6 writer.Write(jsonstr); 7 writer.Flush(); 8 writer.Close(); 9 } 10 11static PlayerDate LoadPlayerData() 12 { 13 string datastr = ""; 14 StreamReader reader; 15 reader = new StreamReader(Application.streamingAssetsPath + "/playerdata.json"); 16 datastr = reader.ReadToEnd(); 17 reader.Close(); 18 return JsonUtility.FromJson<PlayerDate>(datastr); 19 }
上記のコードでjsonファイルのロードとセーブを行っています。
Unity上ではセーブとロードの両方とも正常に動作しています。
IOS端末上ではロードの方は問題なく行えているのですが、セーブすることができません。
エラー
UnauthorizedAccessException: Access to the path "/var/containers/Bundle/Application/4E0B25A7-2290-4C25-A09F-7E67689E864F/com.app/Data/Raw/playerdata.json" is denied. at System.IO.FileStream..ctor (System.String path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share, System.Int32 bufferSize, System.Boolean anonymous, System.IO.FileOptions options) [0x00000] in <00000000000000000000000000000000>:0 at System.IO.StreamWriter.CreateFile (System.String path, System.Boolean append, System.Boolean checkHost) [0x00000] in <00000000000000000000000000000000>:0 at System.IO.StreamWriter..ctor (System.String path, System.Boolean append, System.Text.Encoding encoding, System.Int32 bufferSize, System.Boolean checkHost) [0x00000] in <00000000000000000000000000000000>:0 at GameDirector.SavePlayerDate (PlayerDate playerdate) [0x00000] in <00000000000000000000000000000000>:0 (Filename: currently not available on il2cpp Line: -1)
Xcode上には上記のエラーが表示されています。
ファイルのアクセス権限に問題があるのかと思い、jsonファイルのアクセス権限を変更してみたのですが変化なしです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2020/01/22 08:55 編集