Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

WebView for internal html pages not working in the device

I am trying to run a web app inside a Titanium WebView and, in the emulator, it works perfectly, even for Android. When I compile the project and install the IPA file in my iPhone 4, the App opens but nothing comes up. Only a white screen.

Are the resource files (html, images, etc) need to be placed in a different folder when the app is compiled for iPhone to read them?

— asked November 4th 2010 by Norman Ortiz
  • app
  • html
  • internal
  • web
  • webview
0 Comments

3 Answers

  • as long as the internal html files you user are placed in the resources folder of your titanium project everything should be fine. I did this before and never had problems with it.

    — answered November 4th 2010 by Glenn Tillemans
    permalink
    0 Comments
  • I am also struggling with this issue. It seems to be a pretty complicated set of variables; it doesn't occur when the WebView is at the top level (a SplitWindow), but does in windows created later. It's also specific to local HTML files displayed using the "url" property. I'm hypothesizing this has something to do with the Resources directory structure.

    I'm currently working around the issue by reading the HTML through the filesystem API and passing it to the view:

    
    var htmlFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'html', 'index.html');
    
    var webView = Ti.UI.createWebView({
      html: htmlFile.read().text,
      scalesPageToFit: false
    });
    

    Maybe this will work for you?

    — answered December 31st 2010 by Jonathan Chaffer
    permalink
    1 Comment
    • Upon further investigation the problem must have something to do with how file paths are realized in the emulator vs. device. It's not the case sensitivity (good tip though, Tamas), but the fact it's path-related means that this alternative method also works:

      var htmlFile = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, 'html', 'index.html');
      
      var webView = Ti.UI.createWebView({
        url: htmlFile.nativePath,
        scalesPageToFit: false
      });
      

      — commented January 1st 2011 by Jonathan Chaffer
  • Also take in account that the device is case sensitive while the emulator is not. So pay attention on the filename to have the same case ( index.html <> index.HTML )

    — answered January 1st 2011 by Dan Tamas
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.