gpt4 book ai didi

javascript - WkWebView Evaluatejavascript 返回不支持的类型错误

转载 作者:行者123 更新时间:2023-12-01 15:04:11 27 4
gpt4 key购买 nike

我正在向 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";

};

最佳答案

尝试将您的 javascript 代码包装到 setTimeout :

webView?.evaluateJavaScript("setTimeout(function() {getURL()}, 1000);")

关于javascript - WkWebView Evaluatejavascript 返回不支持的类型错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42887438/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com