我正在向 javascript 函数发送一个值并得到一个结果。但是,当运行以下代码时,我收到“错误域 = WKErrorDomain 代码 = 5“JavaScript 执行返回了不受支持的类型的结果”UserInfo={NSLocalizedDescription=JavaScript 执行返回了不受支持的类型的结果}”错误;
webView?.evaluateJavaScript("getURL()") { (result, error) in
if let error = error
{
print("\(error)");
return
}
if let song = result as? String
{
print("\(song)");
}
}
和javascript代码如下;
function getURL(){
CloudKit.configure({
containers: [{
// To use your own container, replace containerIdentifier and apiToken
containerIdentifier: 'iCloud.com.hello.myapp',
apiToken: 'myApiKey',
environment: 'development'
}]
});
console.log("cloudkitloaded");
var self = this;
console.log("get default container");
var container = CloudKit.getDefaultContainer();
console.log("set publicDB");
var publicDB = container.publicCloudDatabase;
self.items = ko.observableArray();
// Fetch public records
// self.fetchRecords = function() {
console.log("fetching records from " + publicDB);
var query = { recordType: 'Musics'};
// Execute the query.
return publicDB.performQuery(query).then(function(response) {
if(response.hasErrors) {
console.error(response.errors[0]);
return;
}
var records = response.records;
var numberOfRecords = records.length;
if (numberOfRecords === 0) {
console.error('No matching items');
return;
}
console.log(records.length + " records")
//console.log(records[0].fields.Song_File.value.downloadURL);
self.items(records);
myVar = records[emre].fields.Song_File.value.downloadURL;
document.getElementById('someId').innerHTML = myVar;
});
return "emre";
};