In Unity, can I load a local (/Resources folder) website to safari on an ipad?

This works fine on a Mac, opening up a wepage from my Resources folder.

string path = "file://"+(Application.dataPath)+"/Resources/testsite.html";
    void OnGUI(){
        if(GUI.Button(new Rect(20, 20, 100, 100), "site")){

but when I try to load this on an iPhone or iPad, it doesn't seem to work.
Am I accessing the address incorrectly for iOS using "file://"?
If this is not possible, is there an alternative way I can load a locally stored website on an iOS device?


Yes you can, but you're using wrong folder. The Resources folder is not copied with your build; rather, it is compressed into a single file cotaining all assets from the folder. To actually copy some files into your app, use StreamingAssets folder (http://docs.unity3d.com/Documentation/ScriptReference/Application-streamingAssetsPath.html). This folder is simply copied into resulting build, so you can use files in it like normal OS files, including, I suppose, opening them in Safari (I don't know, maybe some iOS quirks can still prevent you from doing that. It definitely works on desktop).


According TO Unity's Manual,

Any files placed in a folder called StreamingAssets in a Unity project will be copied verbatim to a particular folder on the target machine. You can retrieve the folder using the Application.streamingAssetsPath property. For reference, the location of this folder varies per platform:

On a desktop computer (Mac OS or Windows) the location of the files can be obtained with the following code:-

path = Application.dataPath + "/StreamingAssets";

On iOS, you should use:-

path = Application.dataPath + "/Raw";

...while on Android, you should use:-

path = "jar:file://" + Application.dataPath + "!/assets/";

It's always best to use http://docs.unity3d.com/Documentation/ScriptReference/Application-streamingAssetsPath.html to get the location of the StreamingAssets folder, it will always point to the correct location on the platform where the application is running.

For more information have a look into http://docs.unity3d.com/Documentation/Manual/StreamingAssets.html.


You [probably] aren't going to be able to do that.

But with some Objective-C work (and I'm sure there are some easy plugins on the asset store to do this, such as this one), it should be relatively straight forward to push a WebView from within the app itself with whatever html data you want.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .