【发布时间】:2014-03-28 14:21:50
【问题描述】:
我想从目标 c 调用一个 javascript 方法,该方法将返回一些数据。我知道如何使用 JSContext 调用一个简单的方法。但问题是这个方法是通过 XmlHttpRequest 异步调用来下载文件的。我想访问下载的数据变量,但过一段时间就可以使用了。我怎样才能做到这一点。例如:
function download(path)
{
xhr.open("GET", path, true);
xhr.responseType = "arraybuffer";
//asynchronous method call
xhr.onload = function () {
var file = new Uint8Array(xhr.response || xhr.mozResponseArrayBuffer);
var downloaded = populateImageData(file);
//Want to access this variable in objective-c
return downloaded.toString();
};
xhr.send(null);
}
如何在目标 c 中访问下载的变量
【问题讨论】: