SSL_ERROR_SSL(1): operation failed within the library
Deadlock
I assume spotifyRequest will be called on the main thread.
So if the main thread reaches the line
group.wait()
and this line of responseJSON completionHandler was not called yet:
group.leave()
then the main thread is blocked due to the call of group.wait() above.
Due to the blocked main thread group.leave() can't be called. Classical deadlock.
Verfication
Setting a breakpoint to the line
if let safeStatus = status {
shows that this line is never called.
Minimal Example that is running
As a starting point here the code for a minimal example that delivers a result.
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)
}
}
}
This gives as output in the console:
result: Optional(["access_token": XXX, "scope": user-read-email user-read-private, "token_type": Bearer, "expires_in": 3600]) error: nil
see Screenshot:
ATS Settings in info.plist
Spotify offers a valid TLS certificate chain on their server. So there is no need for ATS settings in info.plist.
SSL Warnings in Console
I get the same SSL warnings in the console when I run the application on an iOS 12 simulator like you. Nonetheless the connection is established and the request delivers data. Perhaps this is gone in one of the next betas.
How to fix [BoringSSL] nw_protocol_boringssl_error(1584), Lower protocol stack error: 54 in Xcode Project v-10.1
Those error messages are just network debugging stuff you can safely ignore. On the other hand, the screen going black is just the normal iOS behaviour, and you can turn it off with:
UIApplication.shared.isIdleTimerDisabled = true
This will prevent the screen from dimming and turning off after inactivity periods. Set the value back to false as soon as the functionality is not needed anymore, otherwise your users will get really upset about their battery life.
Related Topics
Lsapplicationqueriesschemes and Derived Data
Accessing Bundle of Main Application While Running Xctests
How to Unwrap Optional<Optional<T>> in Swift 1.2
How to Write to a Variable from Within The Firebase Getdocument Function (Swift)
Should I Keep Extensions in Their Own "Extensions" File
Alamofire Post Request with JSON Encoding
How to Create a Single Page Vertical Scrolling Pdfview in Swift
How to Observe Object's Property in Rxswift
Xcode 9.2 Is Not Showing Swift 4.1
Scenekit - Why Scnlight Created Automatically in Scnscene
Swift Cannot Invoke '*' with an Argument List of Type '(Int, Int)'
Swift Playground with Debugger Support
Tableview Image Content Selection Color
Swift - How to Deal with Uncaught Exception
Emitting a Warning for a Deprecated Swift Protocol Method in Implementing Types