gpt4 book ai didi

swift - 当我尝试发出 GET 请求时出现 "Execution was interrupted, reasno: EXC_BAD_INSTRUCTION"错误

转载 作者:行者123 更新时间:2023-11-30 10:36:26 25 4
gpt4 key购买 nike

我正在尝试在我的 Playground 上运行它:

func getWeatherForecast(){
let Endpoint : String = "http://dataservice.accuweather.com/currentconditions/v1/{}"
let url = URL(string:Endpoint)

let parameters = ["apikey":"API_KEY"] as [String:Any?]
var urlRequest = URLRequest(url:url!)
do
{urlRequest.httpBody = try JSONSerialization.data(withJSONObject: parameters, options: .prettyPrinted)
} catch {
print("error")
}

let task = URLSession.shared.dataTask(with: urlRequest) {(data, response, error) in
do {
let json = try JSONSerialization.jsonObject(with: data!, options: [])
print("The Response is : ",json)
} catch {
print("JSON error: \(error.localizedDescription)")
}
}
task.resume()
}
getWeatherForecast()

然后我不断收到以下两个错误:

error: Execution was interrupted, reason: EXC_BAD_INSTRUCTION 
(code=EXC_I386_INVOP, subcode=0x0).
The process has been left at the point where it was interrupted, use
"thread return -x" to return to the state before expression

我尝试了运行此 API 调用的多种变体,但我无法弄清楚我的代码出了什么问题。有人可以帮忙吗?我只是想做一个简单的 GET 但它似乎一直告诉我“ fatal error :在解包可选值时意外发现 nil”我觉得我已经正确解包了。

任何帮助将不胜感激。谢谢!

最佳答案

您正在调用的“http”网址已被 Apple 阻止,因为它不安全。您必须使用“https”或在 plist 文件中临时允许它。

关于swift - 当我尝试发出 GET 请求时出现 "Execution was interrupted, reasno: EXC_BAD_INSTRUCTION"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57896413/

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