Swift:如何对服务进行API调用,但不等待响应

问题描述 投票:0回答:2

我有一个带有列表通知的collectionviewcontroller。每次单击通知时,我都会将用户发送到适当的控制器。我想做的是单击行之后,我想进行API调用,而不是等待响应。这个API调用只是将这一行标记为READ,所以我不需要等待服务器的响应,也不想让用户等待。我正在使用okhttp进行API调用。这可能吗?

ios swift rest api okhttp
2个回答
1
投票

使您的代码请求在后台队列中像[]一样异步异步>]

      DispatchQueue.global(qos: .background).async {
        print("This is run on the background queue")
        yourApiMethod() }

0
投票

OKHttp是为Android设计的,iOS平台上没有OKHttp。您可以使用OKHttp等效库Alamofire。 Alamofire的请求代码是这样的。

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