2016-07-01 3 views
2

Ich habe versucht, das Spotify ioS SDK-Lernprogramm (https://developer.spotify.com/technologies/spotify-ios-sdk/tutorial/) zu befolgen. Nachdem eine Anmelde-URL mithilfe der folgenden SPTAuth-Methoden erstellt wurde, wird in der praktischen Einführung überprüft, ob die Anmelde-URL eine gültige Spotify-Autorisierungs-URL ist: SPTAuth.defaultInstance().canHandleURL(loginURL). Jedoch gibt diese Methode falsch, mich zu verhindern, dass die Protokollierung der Benutzer inSpotify Anmelde-URL von der .canHandle-Methode abgelehnt

Hier ist der Code, der die Anmeldungs ​​URL setzt.

SPTAuth.defaultInstance().clientID = "3d9c120475a047fab9b1d735ca68dce8" 
    SPTAuth.defaultInstance().redirectURL = NSURL(string: "second-test-spotify://callback") 
    SPTAuth.defaultInstance().requestedScopes = [SPTAuthStreamingScope] 
    var loginURL = SPTAuth.defaultInstance().loginURL 

ich auch diese alternative Klassenmethode versucht, die Login-URL zu setzen, die hat auch nicht funktioniert.

let loginURL = SPTAuth.loginURLForClientId("3d9c120475a047fab9b1d735ca68dce8", withRedirectURL: NSURL(string: "second-test-spotify://callback"), scopes: [SPTAuthStreamingScope], responseType: "token") 

Und hier ist der Login-URL durch beide Methoden zurück:

spotify-action://authorize?client_id=3d9c120475a047fab9b1d735ca68dce8&scope=streaming&redirect_uri=second-test-spotify%3A%2F%2Fcallback&nosignup=true&nolinks=false&response_type=token 

in Swift Mein Code ist, obwohl das Spotify SDK in Objective C ist, da ich einen Überbrückungs Header verwendet.

Antwort

0

Ich erkannte, dass ich die Funktion openURL, die die .canHandle-Methode enthält, falsch aufruft. Ich zog meinen Code in die AppDelegate.swift Datei und ersetzt die openURL Funktionsdefinition mit dieser Funktion Definition:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool { Dann rief ich application.openURL nach dem LoginUrl zu schaffen und es funktioniert einwandfrei.