我正在尝试从spotify sdk中的目标c重新创建示例代码到Swift。
这是我的代码
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
let kClientId = "8b6f7fc911d844dd8abfb08551423d9f"
let kCallbackURL = "byse-test-login://callback"
let kTokenSwapURL = ""
var session:SPTSession?
var player:SPTAudioStreamingController?
func delay(delay:Double, closure:()->()) {
dispatch_after(
dispatch_time(
DISPATCH_TIME_NOW,
Int64(delay * Double(NSEC_PER_SEC))
),
dispatch_get_main_queue(), closure)
}
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
GMSServices.provideAPIKey("AIzaSyBQJYs_f6NkSJvYf9EPgF2QoNyAZjLnas4")
// Override point for customization after application launch.
var auth = SPTAuth.defaultInstance()
var loginURL = auth.loginURLForClientId(kClientId, declaredRedirectURL: NSURL(string: kCallbackURL), scopes: [SPTAuthStreamingScope])
// Opening a URL in Safari close to application launch may trigger
// an iOS bug, so we wait a bit before doing so.
delay(0.1) {
application.openURL(loginURL)
return
}
return true
}
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
// Ask SPTAuth if the URL given is a Spotify authentication callback
if (SPTAuth.defaultInstance().canHandleURL(url, withDeclaredRedirectURL: NSURL(string:kCallbackURL))) {
SPTAuth.defaultInstance().handleAuthCallbackWithTriggeredAuthURL(url, tokenSwapServiceEndpointAtURL: NSURL(string: kTokenSwapURL), callback: { (error, session) -> Void in
if (error != nil) {
println("*** Auth error: \(error)")
return
}
self.playUsingSession(session)
})
return true
}
return false
}
func playUsingSession(session:SPTSession) {
// Create a new player if needed
if (self.player == nil) {
self.player = SPTAudioStreamingController()
}
self.player?.loginWithSession(session, callback: { (error) -> Void in
if (error != nil) {
println("*** Enabling playback got error: \(error)")
return
} else {
SPTRequest.requestItemAtURI(NSURL(string: "spotify:album:3vGtqTr5he9uQfusQWJ0oC"), withSession: session, callback: { (error, album) -> Void in
if (error != nil) {
println("*** Album lookup got error \(error)")
return
}
self.player?.playTrackProvider(album as SPTAlbum, callback: nil)
})
}
})
}
到目前为止这些都是我的错误。
could you identify what may have caused this?
谢谢大家,非常感谢帮助