I am following this tutorial on how to rename a Swift controller. My controller was previously named FirestViewController. It is now named LoginViewController.
I know the rename worked because the project builds and runs correctly in the virtual environment. However the ViewDidLoad
function that holds my Facebook Login code does not work. I am using the Swift Cocoapods SDK.
Any ideas as to why the app runs but the Facebook Login button is missing would be greatly appreciated.
EDIT: Here is my new LoginViewController code file:
import UIKit
import FacebookCore
import FBSDKCoreKit
import FBSDKLoginKit
import FacebookLogin
class LoginViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
//let loginButton = FBSDKLoginButton
let loginButton = FBSDKLoginButton()
loginButton.center = view.center
view.addSubview(loginButton)
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError! ) {
/*
Check for successful login and act accordingly.
Perform your segue to another UIViewController here.
*/
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "nextView") as! SecondViewController
self.present(nextViewController, animated:true, completion:nil)
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
// Actions for when the user logged out goes here
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
EDIT 2: New code after suggested changes:
import UIKit
import FacebookCore
import FBSDKCoreKit
import FBSDKLoginKit
import FacebookLogin
class LoginViewController: UIViewController, FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let loginButton = FBSDKLoginButton()
loginButton.delegate = self
loginButton.center = view.center
view.addSubview(loginButton)
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error! ) {
/*
Check for successful login and act accordingly.
Perform your segue to another UIViewController here.
*/
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let nextViewController = storyBoard.instantiateViewController(withIdentifier: "nextView") as! SecondViewController
self.present(nextViewController, animated:true, completion:nil)
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
// Actions for when the user logged out goes here
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
I fixed the issue thanks to the pointers by Kevin Vaughan. After adding break points to my code, I noticed it was never breaking at these points suggesting the code was not being executed.
I had to update the absolute path to the view controller for the storyboard to finally read the code.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.