如何从API响应中获取特定响应并将其与深链接Swift 5一起使用
我正在使用诸如此类的post方法
'成功{
收到API的回复 短链接= pahjt7;
状态= 200;
}'
我只想在我的URL上使用快捷链接来使用深层链接概念共享。
这是我的邮政方法守则,在其中我从API
中得到响应
func postRequest(latitude:Double,longitude:Double) {
guard let url = URL(string: "http://i.Mallangtech.com/api/Url") else{
return
}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/Json", forHTTPHeaderField: "Content-Type")
let body:[String: AnyHashable] = [
"status": 200,
"shortlink":"okko"]
request.httpBody = try? JSONSerialization.data(withJSONObject: body, options: .fragmentsAllowed)
//hiting api
let task = URLSession.shared.dataTask(with: request) { data, _, Error in
guard let data = data, Error == nil else {
return
}
do{
let response = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
print("Success\(response)")
}
catch{
print (error)
}
}
task.resume()
}
```
I'm Receiving Response from api using post method like this
'Success{
shortlink = pAHJt7;
status = 200;
} '
I want to use only shortlink with my url to share using deep linking concept.
Here is my code of post method in which I'm getting response from api
func postRequest(latitude:Double,longitude:Double) {
guard let url = URL(string: "http://i.Mallangtech.com/api/Url") else{
return
}
var request = URLRequest(url: url)
request.httpMethod = "POST"
request.setValue("application/Json", forHTTPHeaderField: "Content-Type")
let body:[String: AnyHashable] = [
"status": 200,
"shortlink":"okko"]
request.httpBody = try? JSONSerialization.data(withJSONObject: body, options: .fragmentsAllowed)
//hiting api
let task = URLSession.shared.dataTask(with: request) { data, _, Error in
guard let data = data, Error == nil else {
return
}
do{
let response = try JSONSerialization.jsonObject(with: data, options: .allowFragments)
print("Success\(response)")
}
catch{
print (error)
}
}
task.resume()
}
```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
让我们将此功能分为4个步骤。
您已经完成了步骤1。
对于步骤2,您可以使用
uiactivityViewController
。您可以参考执行。对于步骤3和4,您需要为深链接配置并在
SceneDelegate
中处理它。请参阅 this ,您可以从启动视图控制器带有所需参数的scenelegate
。Lets divide this feature into 4 steps.
You have already done the step 1.
For step 2, You can use
UIActivityViewController
. You can refer this for its implementation.For step 3 and 4, You need to configure for deep link and handle it inside
SceneDelegate
. Refer this and you can launch a view controller fromSceneDelegate
with required params.