我遇到UIWebView
的问题。我正在尝试加载HTML字符串,该字符串将加载其他下载的文件(js文件,css,html和xml文件),以便在UIWebview
内部的自定义播放器中加载一些内容。同一件事在android中起作用,所以我不认为文件中有问题。
但是在iOS中,它显示白页。我在堆栈溢出中尝试了其他类似问题的所有建议。
我已经检查了文件是否已正确下载。一切似乎都很好。我可以看到目录中的文件并打开它。我也将NSLogs
放在webViewDidFinishLoad
方法中进行检查并得到执行。我既找不到任何解决方案,也找不到问题所在。
self.webContentView.delegate = self;
NSString* html = [player getHTMLString];
NSString* baseURL = [player getBaseURLPath];
[self.webContentView loadHTMLString:html baseURL: [NSURL URLWithString: baseURL]];
html字符串是根据存储在资源中的模板构建的。 baseURL不是零或不正确。 html字符串-
<!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>