2017-03-11 4 views
-1

Wie gehe ich nach facebook login zum anderen viewcontroller? Was sollte in Main.storyboard getan werden?Wie gehe ich nach facebook login zum anderen Viewcontroller?

Hier ist meine AppDelegate.swift

import UIKit 

import FBSDKCoreKit 

@UIApplicationMain 

class AppDelegate: UIResponder, UIApplicationDelegate { 

    var window: UIWindow? 


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 

     FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) 

     return true 
    } 

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool { 

     return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as! String!, annotation: options[UIApplicationOpenURLOptionsKey.annotation]) 
    } 

    func applicationDidBecomeActive(_ application: UIApplication) { 
     FBSDKAppEvents.activateApp() 
    } 

} 

Hier ist ViewController.swift

import UIKit 
import FBSDKLoginKit 

class ViewController: UIViewController, FBSDKLoginButtonDelegate { 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     let loginButton = FBSDKLoginButton() 
     loginButton.center = self.view.center 
     view.addSubview(loginButton) 
    } 

    func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) { 

     if error != nil { 
     print("Something went wrong... \(error)") 
      return 
     } 

     print("Successfully logged in!") 
    } 

    func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) { 

     print("Successfully logged out!") 
    } 
} 

Antwort

0

Du bist wahrscheinlich etwas wie folgt aussehen:

if(FBSDKAccessToken.currentAccessToken() != nil) { 
    let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil) 
    let vc = storyboard.instantiateViewController(withIdentifier: "myViewController") 
    self.navigationController?.push(vc, animated: true) 
} 

Was das Snippet tut Überprüfen Sie, ob der Benutzer über Facebook eingeloggt ist (ich nehme an, Sie verwenden das SDK), und wenn dies der Fall ist, instan tippe ein VC vom Storyboard und drücke es mit dem Navigationscontroller. Wo Sie das hinstellen möchten, ob Sie den VC anders darstellen möchten, etc ..., liegt ganz bei Ihnen, da der Fluss Ihrer App sie stark informieren wird.

0

Versuchen Sie dies in Ihrem ViewController.swift:

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) { 
     if error == nil && !result.isCancelled{ 
      let storyboard = UIStoryboard(name: "Main", bundle: nil) 
      if let vc = storyboard.instantiateInitialViewController(){ 
       self.present(vc, animated: true, completion: nil) 
      } 
     } 
    } 
Verwandte Themen