Forum Visual Studio

Content files not deployed in bundle folder [iOS]

I want to show the content of an html file in a UIWebView. The html file uses a separate javascript file. When I deploy my app to the simulator, the html file is loaded in the webview, but the javascript is not loaded. When I check the simulator folders I can find my app and the database in the Library folder, however there's no trace of my two content files?

The html file is read to a string. When debugging in vs2013, the string does contain the file content and the UIWebView does display that content:
string html = File.ReadAllText("Content/cloud.html");
This puzzles me, since the there's no trace of the files on the simulator.

I've tried the script calls
<script src="tagcanvas.js" type="text/javascript"></script>
<script src="Content\tagcanvas.js" type="text/javascript"></script>
<script src="\Content\tagcanvas.js" type="text/javascript"></script>
<script src=".\Content\tagcanvas.js" type="text/javascript"></script>
None seem to work.

On the simulator the app is deployed to folder (see image):
Macintosh ▸ Users ▸ alex ▸ Library ▸ Developer ▸ CoreSimulator ▸ Devices ▸ 46DCC892-6428-4D03-A51D-C7A89E4834DB ▸ data ▸ Applications ▸ 6D6FD6D9-BD0B-461D-BAF3-3CCBBC0432EF

So where are my content files? How can the html file be read, when its not in the bundle folder?
Any help would be much appreciated!

Posts

  • VictorKzamVictorKzam BRMember

    I'm having the same problem. If you know the solution please share.

  • VictorKzamVictorKzam BRMember

    You must add all files as "Content". You select file by file and choose "Build Action" and changes to "Content".

  • RubenKortRubenKort SRMember

    Victor,

    Thanks for your response. I've finally figured it out...

    Yes, you are right, build action of the files should be set to "Content" and Copy always/if newer (as I already did)

    This will copy the files inside your app bundle.
    That was what I missed! When I opened myApp.app in the simulator -lo and behold- the content folder and the two files are there. I expected the content folder in the app folder, not in the bundle...

    Now using the .js from the html was still not working, though I now know where the html file resides. The solution was using a full path in the html script tag:
    <script src="[scriptlocation]/tagcanvas.js" type="text/javascript"></script>

    string html = File.ReadAllText("Content/cloud.html"); html = html.Replace("[scriptlocation]", NSBundle.MainBundle.BundlePath + "/Content");

    Now the .js is proparly loaded.

Sign In or Register to comment.