2017-12-19 40 views
0

私はGoogle、Facebook & Spotifyを使用しているアプリを作っています。だから、私は私のアプリDelegate.swiftSwift3で同じApp DelegateでGoogle、Facebook、およびSpotifyを使用する方法iOS

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委任で唯一の戻り値と組み合わせることができますか?ありがとうございました。

答えて

0

この

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 



} 
+0

おかげで男を試してみてください、それが動作します! – user2786

関連する問題