System.UnauthorizedAccessException during file write

I’m getting an authorization error on the following code on an iphone5 but not an iphone 4s when trying to write an assetbundle to the streamingassets path. I’ve tried deleting the app and restarting the phone but still it crashes with the error below. Is this a unity problem or some phone setting issue? or something to do with the bytes not arriving?

url=http://somepass:somelogin@www.website.com/hat2_tophat.unity3d;
 var www = new WWW(url);
    yield www;


    var filepath= Application.streamingAssetsPath + "/"+prop.name+".unity3d"; 
    	Debug.Log("filepath="+filepath);
    		File.WriteAllBytes(filepath, www.bytes);
	

Unhandled Exception: System.UnauthorizedAccessException: Access to the path "/var/mobile/Applications/32CBA0EC-F1A9-428D-8B90-5B8FE8D156AC/improvapp.app/Data/Raw/hat2_tophat.unity3d" 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, FileAccess access, FileShare share, Int32 bufferSize) [0x00000] in <filename unknown>:0 
      at System.IO.File.Create (System.String path, Int32 bufferSize) [0x00000] in <filename unknown>:0 
      at System.IO.File.Create (System.String path) [0x00000] in <filename unknown>:0 
      at System.IO.File.WriteAllBytes (System.String path, System.Byte[] bytes) [0x00000] in <filename unknown>:0 
      at world17dabear_nodebugs+$loadObject$954+$.MoveNext () [0x00000] in <filename unknown>:0

You need to use Application.persistentDataPath, as the path to all your files. You do not have read/write access outside of that path
The wonders of application specific permissions XD

Hope this helps,
Benproductions1

PS: Yes this is both IOS and Android

Write to Application.persistentDataPath. It’s explicit purpose is to provide a location where you can safely write custom data to at run-time.

Application.streamingAssetsPath has only read but not write autority.
Read file from Application.streamingAssetsPath, you need use : File.OpenRead (filepath)

byte[] bytes = null;
using (FileStream fileStream = File.OpenRead (filepath))
 {
        bytes = new byte[fileStream.Length];
        fileStream.Read(bytes, 0, int.Parse(fileStream.Length + ""));
        fileStream.Close();
        fileStream.Dispose();
}

You can refer to this : https://forum.unity3d.com/threads/accessing-files-in-streamingassets-on-ios-access-denied.261994/