[英]Trigger segue after facebook login
我正在使用Facebook登錄名來開發我的第一個應用程序,並且登錄后無法觸發segue。facebook登錄名會觸發就好,然后登錄我,然后將其轉儲回登錄VC 。
這是我觸發segue的地方:
func loginButtonDidCompleteLogin(_ loginButton: LoginButton, result: LoginResult) {
switch result {
case .failed(let error):
print(error)
break
case .success(_,_,_):
print("login succeeded!")
self.performSegue(withIdentifier: "SearchVC", sender: self.user)
case .cancelled:
print("Canceled!")
}
}
這是我的其他FB登錄方法:
func facebookButtonClicked(sender: UIButton) {
let loginManager = LoginManager()
loginManager.logIn(readPermissions: [.publicProfile], viewController: self) { loginResult in
switch loginResult {
case .failed(let error):
print(error)
case .cancelled:
print("User cancelled login")
case .success(let grantedPermissions, let declinedPermissions, let accessToken):
print("Logged in")
self.getFBUserData()
}
}
}
func getFBUserData() {
if FBSDKAccessToken.current() != nil {
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, email"]).start(completionHandler: { (connection, result, error) -> Void in
if error == nil {
self.userData = result as! [String : AnyObject]
print(result!)
print(self.userData)
}
})
}
}
我的Segue:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "SearchVC", let searchVC = segue.destination as? SearchVC {
searchVC.user = sender as? User ?? User()
}
}
在我的應用程序委托中:
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}
func applicationWillResignActive(_ application: UIApplication) {
FBSDKAppEvents.activateApp()
}
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any] = [:]) -> Bool {
return SDKApplicationDelegate.shared.application(app, open: url, options: options)
}
func applicationDidBecomeActive(application: UIApplication) {
// Call the 'activate' method to log an app event for use
// in FB analytics and advertising reporting.
AppEventsLogger.activate(application)
// ...
}
該segue在IB中以標識符“ SearchVC”連接
編輯:我最初嘗試在FBSDKGraphRequest的完成塊中執行segue,但它也不會觸發
我不是在問如何執行segue,因為建議的重復問題表明
您應該在FBSDKGraphRequest
完成中調用performSegue方法。
func getFBUserData(){
if((FBSDKAccessToken.current()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, email"]).start(completionHandler: { (connection, result, error) -> Void in
if (error == nil){
self.userData = result as! [String : AnyObject]
print(result!)
print(self.userData)
self.performSegue(withIdentifier: "SearchVC", sender: self)
}
})
}
}
}
該項目已被竊聽。 我還有另一個問題,就是沒有在這里和那里執行代碼以及其他一些雜項塊。 刪除我的LoginVC
文件並重新創建它可以解決所有問題
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.