- Home /
iOS - WWW Doesn't work on Local Load
Hello,
I'm building a local save/load system for textures for iOS, and I'm working with both .NET and WWW systems. My WWW system doesn't seem to work for loading on iOS. Both work fine in the Editor.
.NET (Works):
var pathtype = GetDataPath();
var path = pathtype + "/" + dir;
var filepath = path + "/" + filename;
var imgRaw = File.ReadAllBytes(filepath);
var img = new Texture2D(size.x, size.y);
img.LoadImage(imgRaw);
WWW (Doesn't Work):
var pathtype = GetDataPath();
var path = pathtype + "/" + dir;
var filepath = "file://" + path + "/" + filename;
var www = new WWW(filepath);
var img = www.texture;
GetDataPath() basically just passes in the persistentDataPath or just a normal dataPath depending if I'm running it on iOS or in the Editor.
My debugger says it has been loaded, and the directory looks okay to me:
.NET (Works):
/var/mobile/Containers/Data/Application/***/Documents/my_dir/profile.png
WWW (Doesn't Work):
file:///var/mobile/Containers/Data/Application/***/Documents/my_dir/profile.png
Out of curiosity, if the .NET version works, why do you want to use WWW?
Because I'm also using this system to load AudioClips to, and I can't figure out how to do that via .NET, whereas WWW has classes to do it. But I can't get it to work on iOS
To do it without WWW you'd need to find a library to decode the file into a format that AudioClip.SetData can accept (unless there's some .NET/$$anonymous$$ono class that can do it). It's doable but seems like it could be a mess, so WWW is indeed preferable.
What's the output when you do Debug.Log(www.error)?
Yeah I thought that would be the case. Ideally, I'm trying to move from .NET, to WWW. When I run the program in Editor, no errors and the textures load fine.
But on iOS, the textures load as a question mark (Doc states: If the data is not a valid image, the generated texture will be a small image of a question mark). And Debug.Log isn't saying anything. So theres not error in terms of finding the image - so the directory must be okay.
Could it be that because I'm saving the image initially via .NET, which may cause a corruption? Yet, it works fine on the editor.
var bytes = img.EncodeToPNG();
File.WriteAllBytes( path, bytes );
Try putting the loading in a coroutine and doing yield www; between creating the www and accessing .texture
Your answer
Follow this Question
Related Questions
Dinamic name for data save 0 Answers
Webplayer crash on LoadImageIntoTexture call 1 Answer
Is it possible to load a script from a url? 1 Answer
the texture appear rubbish 1 Answer
Load audioclip from folder on computer into game, in runtime 3 Answers