如何在 Swift 3 iOS 中的同一个 App Delegate 中使用 Google、Facebook 和 Spotify

How to use Google, Facebook & Spotify in same App Delegate in Swift3 iOS

我正在制作一个应用程序,我正在使用 Google、Facebook 和 Spotify。所以,我在我的应用程序中使用以下代码 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 中仅结合一个 return 值?谢谢。

试试这个

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



}