我正在制作一个应用程序,我正在使用Google,Facebook和Spotify。所以,我在我的App Delegate.swift中使用下面的代码
func application(_ application: UIApplication,
open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool
{
//For Google & Facebook
let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
let annotation = options[UIApplicationOpenURLOptionsKey.annotation]
let googleHandler = GIDSignIn.sharedInstance().handle(
url,
sourceApplication: sourceApplication,
annotation: annotation )
let facebookHandler = FBSDKApplicationDelegate.sharedInstance().application (
application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation )
return googleHandler || facebookHandler
//For Spotify
if SPTAuth.defaultInstance().canHandle(url) {
SPTAuth.defaultInstance().handleAuthCallback(withTriggeredAuthURL: url) { error, session in
// This is the callback that'll be triggered when auth is completed (or fails).
if error != nil {
print("*** Auth error: \(error)")
return
}
else {
SPTAuth.defaultInstance().session = session
}
NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "sessionUpdated"), object: self)
}
}
return false
}
问题:如何在App Delegate中仅与一个返回值结合使用?谢谢。
试试这个
func application(_ application: UIApplication,
open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool
{
//For Google & Facebook
let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String
let annotation = options[UIApplicationOpenURLOptionsKey.annotation]
var Spotify = false
//For Spotify
if SPTAuth.defaultInstance().canHandle(url)
{
SPTAuth.defaultInstance().handleAuthCallback(withTriggeredAuthURL: url)
{ error, session in
// This is the callback that'll be triggered when auth is completed (or fails).
if error != nil
{
print("*** Auth error: \(error)")
}
else
{
SPTAuth.defaultInstance().session = session
Spotify = true
}
NotificationCenter.default.post(name: NSNotification.Name.init(rawValue: "sessionUpdated"), object: self)
}
}
let googleHandler = GIDSignIn.sharedInstance().handle(
url,
sourceApplication: sourceApplication,
annotation: annotation )
let facebookHandler = FBSDKApplicationDelegate.sharedInstance().application (
application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation )
return googleHandler || facebookHandler || Spotify
}