问问题
32132 次
2 回答
16
僵局
我假设将在主线程上调用 spotifyRequest。
所以如果主线程到达该行
group.wait()
并且这行 responseJSON completionHandler 还没有被调用:
group.leave()
然后由于上面的 group.wait() 调用,主线程被阻塞。由于阻塞的主线程 group.leave() 不能被调用。经典的僵局。
验证
给行设置断点
if let safeStatus = status {
表明这条线永远不会被调用。
正在运行的最小示例
作为此处的起点,提供结果的最小示例的代码。
import UIKit
import Alamofire
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.contactSpotify {
print ("result: \(String(describing: $0)) error: \(String(describing: $1))")
}
}
func contactSpotify(completion: @escaping ([String: Any]?, Error?) -> Void) {
let url = URL(string: "https://accounts.spotify.com/api/token")!
Alamofire.request(url,
method: .post,
parameters: ["grant_type": "refresh_token",
"client_id": "<someClientId>",
"refresh_token": "<someRefreshToken>",
"client_secret": "<someClientSecret>"])
.validate()
.responseJSON { response in
guard response.result.isSuccess else {
completion(nil, response.result.error)
return
}
completion(response.result.value as? [String: Any], nil)
}
}
}
这在控制台中作为输出给出:
result: Optional(["access_token": XXX, "scope": user-read-email user-read-private, "token_type": Bearer, "expires_in": 3600]) error: nil
info.plist 中的 ATS 设置
Spotify 在其服务器上提供有效的 TLS 证书链。所以 info.plist 中不需要 ATS 设置。
控制台中的 SSL 警告
当我在像您这样的 iOS 12 模拟器上运行应用程序时,我在控制台中收到相同的 SSL 警告。尽管如此,连接已经建立并且请求传递数据。也许这在下一个测试版中消失了。
于 2018-08-21T20:11:45.747 回答
0
在任何响应调用中,我在模拟器中对 codegen Swagger 有同样的警告。但一切都奏效了。仅当我添加环境变量隐藏奇怪的不需要的 Xcode 日志时,此警告才消失
于 2019-01-21T11:05:24.750 回答