I am facing a problem with UIWebView
. I am trying to load an HTML string which will load other downloaded files(js files, css, html and xml files) to load some contents in custom player inside UIWebview
.Same thing is working in android so I don't think there is issue in files.
But in iOS it showing a white page. I have tried all suggestions in other similar questions in stack overflow.
I have already checked if the files are properly being downloaded or not. Everything seems fine. I can see the files in directories and open it. I have also put NSLogs
inside webViewDidFinishLoad
method to check and its also getting executed.I can neither find any solutions on this nor identify the problem.
self.webContentView.delegate = self;
NSString* html = [player getHTMLString];
NSString* baseURL = [player getBaseURLPath];
[self.webContentView loadHTMLString:html baseURL: [NSURL URLWithString: baseURL]];
html string is build from a template stored in resources. baseURL is not nil or incorrect. html string -
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content='width=device-width'>
<title>{{lessonTitle}}</title>
<script type="text/javascript" language="javascript" src="file://{{icplayerPath}}/javascript/jquery-1.7.1.min.js"></script>
<script type="text/javascript" language="javascript" src="file://{{icplayerPath}}/icplayer/icplayer.nocache.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
messageStyle: "none",
TeX: {imageFont: null, extensions: ["mhchem.js", "AMSsymbols.js", "AMSmath.js"]},
extensions: ["tex2jax.js", "forminput.js"],
skipStartupTypeset: true,
jax: ["input/TeX","output/HTML-CSS"],
playerObject: "player"
});
</script>
<script type="text/javascript" src="file://{{icplayerPath}}/javascript/MathJax/MathJax.js"></script>
<script language="javascript">
var player1;
var scorm;
function icOnAppLoaded(){
// Load assessment
{{#createBook}}
player1 = icCreateBook('_icplayer', {{withCover}});
{{/createBook}}
{{^createBook}}
player1 = icCreatePlayer('_icplayer');
{{/createBook}}
{{#lessonPages}}
if (player1.hasOwnProperty('setPages'))
{
player1.setPages('{{lessonPages}}');
}
{{/lessonPages}}
{{#lessonStateString}}
stateString = "{{{lessonStateString}}}";
player1.setState(stateString);
{{/lessonStateString}}
player1.load('file://{{lessonMainXmlPath}}');
player1.onPageLoaded(function(){
if (window.parent != null && window.parent.postMessage != null) {
var height = $('#_icplayer').css('height');
var width = $('#_icplayer').css('width');
var message = "resize: width=" + width + ";height=" + height;
var viewport = document.querySelector("meta[name=viewport]");
viewport.setAttribute('content', 'width=' + parseInt(width));
$('#lesson').width(width);
$('#lesson').css('margin', '0 auto');
window.parent.postMessage(message, '*');
var pageNo = player1.getPlayerServices().getCurrentPageIndex();
var theUrl = "mLibro://pageLoaded/"+pageNo;
window.location = theUrl;
alert(theUrl);
}
});
}
function mLibroIOS_getScore(){
if (player1.hasOwnProperty('forceScoreUpdate')) {
player1.forceScoreUpdate()
}
var pu = new PlayerUtils(player1);
var pres = pu.getPresentation();
var scoreNew = pu.getPresentationScore(pres);
return JSON.stringify(scoreNew);
}
</script>
</head>
<!-- max-width:600px -->
<body style="padding:0px;margin:0px">
<div id="lesson">
<div id="_icplayer" style="padding:0px;margin:0px;float:left"></div>
</div>
<div style="clear: both"></div>
</body>
</html>