在创建新的Client-Server tvOS应用程序时,tvOS将不会从我的外部tvml
文件中获取数据。这是错误:ITML <Error>: Failed to load launch URL with error: (null)
这是main.js
代码
function getDocument(url) {
var templateXHR = new XMLHttpRequest();
templateXHR.responseType = "document";
templateXHR.addEventListener("load", function() {pushDoc(templateXHR.responseXML);}, false);
templateXHR.open("GET", url, true);
templateXHR.send();
return templateXHR;
}
function pushDoc(document) {
navigationDocument.pushDocument(document);
}
App.onLaunch = function(options) {
var templateURL = 'niclasblog.com/appletv/main.tvml';
getDocument(templateURL);
}
App.onExit = function() {
console.log('App finished');
}
我还附上了main.tvml
文件
<document>
<alertTemplate>
<title>Test</title>
<description>This is a test</description>
<button>
<text>Yes</text>
</button>
<button>
<text>No</text>
</button>
</alertTemplate>
</document>
该代码直接来自Apple文档,因此我不知道它为什么不能工作。
发布于 2016-02-09 15:07:17
在您的App.onLaunch函数中,您可以获得BASEURL并使用它加载所有资产:
App.onLaunch = function(options) {
var BASEURL = options.BASEURL;
// etc.
}
您还可以考虑一种加载模板的不同方法。考虑使用DOMParser来解析XML字符串。这样,您就可以编写带有“真实”内容的多行模板字符串。
getDocument(options) {
let parser = new DOMParser();
let templateString = `<?xml version="1.0" encoding="UTF-8" ?>
<document>
<alertTemplate>
<description>${options.translate.errorRandomErrorAlertText}</description>
<button>
<text>${options.translate.utilOk}/text>
</button>
</alertTemplate>
</document>`;
return parser.parseFromString(templateString, "application/xml");
}
我为Apple应用程序编写了一个生成器,它使用的es6还处于开发初期,但可能会帮助您入门。
发布于 2015-11-02 16:14:15
试着替换这个
var templateURL = 'niclasblog.com/appletv/main.tvml';
具有完全限定URI
var templateURL = 'https://niclasblog.com/appletv/main.tvml';
也是
templateXHR.responseType = "document";
并不需要,因为这似乎是默认行为。
https://stackoverflow.com/questions/33288392
复制相似问题