Skip to content

Instantly share code, notes, and snippets.

@fitomad
Created September 2, 2018 15:53
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save fitomad/8ab3508f8935f592640038745623a4fb to your computer and use it in GitHub Desktop.
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
{
let components = URLComponents(url: url, resolvingAgainstBaseURL:false)
// Comprobamos si alguno de los parámetros de URL es el código
// para solicitar un token de acceso.
if let code = components?.queryItems?.filter({ $0.name =="code" }).first?.value
{
// Es un código. Vamos a canjearlo por un token
TraktTVClient.shared.exchange(code: code) { (authenticated: Bool, error: TraktError?) -> Void in
if authenticated
{
// ¡Estupendo! Tenemos un token de acceso y de refresco.
DispatchQueue.main.async
{
self.window?.rootViewController?.dismiss(animated: true)
})
}
}
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment