如何让iphone连接json服务器API进行调试?

问题描述 投票:-1回答:1

我尝试使用json服务器来调用我的API样本。在模拟器中,我使用这段代码成功地调用了API,但当我连接iphone时,它却失败了。

//json-server -w db.json

var request = try self.buildRequestNew(requestHeader: requestHeader, from: route)

let testUrl = route.baseURL.appendingPathComponent("\(route.path)")

if testUrl == URL(string: "https://xxxxxxxxxxx.com.tw/xxxxxxx/rest/test1") {
       request = URLRequest(url: URL(string: "http://localhost:3000/test1")!) //my request change this URL.
       request.httpMethod = "GET"
}

但是当我连接iphone时,它却失败了。我需要做什么和改变什么IP地址来让我的API调用成功。谅谅

ios iphone xcode ip-address json-server
1个回答
0
投票

当在模拟器中运行时。localhost 是你的开发机的地址。在手机上运行。localhost 指的是手机,所以你需要用 Mac 的主机名或 IP 地址来代替。我们不能告诉你那到底是什么,你必须弄清楚,例如从系统偏好设置> 网络。

© www.soinside.com 2019 - 2024. All rights reserved.