【发布时间】:2015-11-25 19:04:27
【问题描述】:
我目前正在关注 Spotify 关于 iOS SDK 的教程。我还将 Objective-C 代码转换为 Swift。
Spotify 想让我运行这段代码:
-(BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// Ask SPTAuth if the URL given is a Spotify authentication callback
if ([[SPTAuth defaultInstance] canHandleURL:url]) {
[[SPTAuth defaultInstance] handleAuthCallbackWithTriggeredAuthURL:url callback:^(NSError *error, SPTSession *session) {
if (error != nil) {
NSLog(@"*** Auth error: %@", error);
return;
}
// Call the -playUsingSession: method to play a track
[self playUsingSession:session];
}];
return YES;
}
return NO;
}
我已将其转换为 Swift:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
if SPTAuth.defaultInstance().canHandleURL(url) {
SPTAuth.defaultInstance().handleAuthCallbackWithTriggeredAuthURL(url, callback: {(error: NSErrorPointer, session: SPTSession) -> Void in
if error != nil {
NSLog("*** Auth error: %@", error)
return
}
playUsingSession(session)
})
return true
}
return false
}
然而,swift 代码包含 2 个错误:
为什么我在遵循 Spotify 的教程时会收到错误消息?是否与将 Objective-C 转换为 Swift 有关?我该如何解决这个问题?
【问题讨论】:
-
我建议您在iOS SDK tutorial page 上发表评论(在底部,单击“显示 cmets”),因为这是报告教程问题的正确位置。
标签: ios spotify cocoalibspotify-2.0