How to correctly read a file from Application.streamingAssetsPath in iOS (works in Android).

Reading a file from StreamingAssets in iOS give this error:

UnauthorizedAccessException: Access to the path "/var/containers/Bundle/Application/5D5684A5-74A8-4E63-83A3-0F6323711262/DecrimentalTest.app/Data/Raw/data01Text.bytes" is denied.
  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.FileStream..ctor (System.String path, FileMode mode) [0x00000] in <filename unknown>:0 
  at DataService.ReadLevelText (System.String file, System.Collections.Generic.List`1 levelText) [0x00000] in <filename unknown>:0 
  at Master.OnEnable () [0x00000] in <filename unknown>:0 
 
(Filename: currently not available on il2cpp Line: -1)

I have code that reads in my level data from a file in the StreamingAssets folder working in Android but it gives an error. I can’t work out what I am doing wrong. Any help appreciated.

My code is:

string file = System.IO.Path.Combine (Application.streamingAssetsPath, "data01.bytes");
DataService.Instance.ReadLevelsComp (file, _levelsInGame);

....

	public void ReadLevelsComp(string file, List<Level> levels)
	{
		byte[] contents;

		// Must use WWW class to read streamingAssets in Android and also File.Exists() will not work on streamingAssets in Android
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
		using (WWW www = new WWW (file))
		{
		while (!www.isDone) { } // wait for 'download'
		if (!string.IsNullOrEmpty(www.error))
		{
		Debug.LogErrorFormat ("ReadFromFile({0}) -- {1}", file, www.error);
		}
		else
		{
		contents = www.bytes;
#else
		if(!File.Exists(file))
		{
			Debug.LogErrorFormat ("ReadFromFile({0}) -- Levels file not found", file);
		} 
		else
		{
			contents = File.ReadAllBytes (file);
#endif	
			if (contents.Length == 0)
			{
                        // Does Stuff here
			}
		} // else (file exists / www error) clause 
#if (UNITY_ANDROID || UNITY_IOS) && !UNITY_EDITOR
		} // using www clause		
#endif	
	}

If I try to use the www class in iOS I get this error:

ReadFromFile(/var/containers/Bundle/Application/5299A248-29A3-4BC1-90D5-ECDDF3A544C9/DecrimentalTest.app/Data/Raw/data02Text.bytes) -- Cannot connect to destination host

Development for Android applications is that good idea? I was searching for tutorials for Android programming and I saw it is not that easy as I was thinking actually I am a beginner programmer of Custom Paper Service | AOneEssays and trying to learn Android applications.

This is indeed a great post,

With Regards,
Protar,
Tutuapp
Kodi
ShowBox Download