我正在创建一个同时使用Spotify登录和Facebook登录的应用程序。他们的两个教程都说要修改AppDelegate.swift文件中的application()。我的问题是两个登录都分别计算函数的返回值(布尔值),我不知道如何组合它们。我的问题是如何使两个日志工作并使用application()中的一个返回值。为清楚起见,每个登录所需的内容如下所示。
spotify SDK想要:
func application(...) -> Bool() {
let auth = SPTAuth.defaultInstance()
let authCallback = { (error : NSError?, session : SPTSession?) -> () in
if (error != nil) {
NSLog("*** Auth Error \(error)")
return
}
auth.session = session
NSNotificationCenter.defaultCenter().postNotificationName("sessionUpdated", object: self)
}
if auth.canHandleURL(url) {
auth.handleAuthCallbackWithTriggeredAuthURL(url, callback: authCallback)
return true
}
return false
}
facebook SDK想要:
func application(...) -> Bool {
var wasHandled = FBAppCall.handleOpenURL(url, sourceApplication:sourceApplication)
// any app-specific handling code here
return wasHandled
}
答案 0 :(得分:0)
这可能不是最佳解决方案,但您可以检查URL是否使用一种类型处理,然后尝试使用下一种类型(如果未处理)。
如果两种类型都无法处理,则返回false
。
例如:
func application(...) -> Bool {
var wasHandled = FBAppCall.handleOpenURL(url, sourceApplication:sourceApplication)
// any app-specific handling code here
if (!wasHandled) {
// spotify code here...
if auth.canHandleURL(url) {
auth.handleAuthCallbackWithTriggeredAuthURL(url, callback: authCallback)
return true;
}
return false;
}
return wasHandled;
}
答案 1 :(得分:0)
对于Spotify登录
YOUR_URL_SCHEME_IDENTIFIER_FOR_SPOTIFY 它与您的ios项目网址计划中提到的字符串相同,并且还包含了MyApplications Redirect URIs。
if ([[url absoluteString] hasPrefix:@"YOUR_URL_SCHEME_IDENTIFIER_FOR_SPOTIFY"]) {
let auth = SPTAuth.defaultInstance()
let authCallback = { (error : NSError?, session : SPTSession?) -> () in
if (error != nil) {
NSLog("*** Auth Error \(error)")
return
}
auth.session = session
NSNotificationCenter.defaultCenter().postNotificationName("sessionUpdated", object: self)
}
if auth.canHandleURL(url) {
auth.handleAuthCallbackWithTriggeredAuthURL(url, callback: authCallback)
return true
}
return false
}