So I have class FBViewController which should show a button log me in and log out (just to test FB login). I integrated this in newly created project and all worked. Then I reworked it into my app and it's not working. Not sure if it has something to do with swift version or sth else... Using Xcode 10.0
import UIKit
import FBSDKLoginKit
class FBViewController: UIViewController, FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let btnFBLogin = FBSDKLoginButton()
btnFBLogin.readPermissions = ["public_profile", "email"]
btnFBLogin.delegate = self
btnFBLogin.center = self.view.center
self.view.addSubview(btnFBLogin)
if FBSDKAccessToken.current() != nil{
print("Logged IN ALREADY")
printInfo()
}else{
print("not logged in")
}
}
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
if error != nil{
print(" error")
// print(error.localizedDescription)
}else if result.isCancelled {
print("User cancelled.")
}
else {
print("Logge IN!")
printInfo()
}
}
func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
print("logged out")
}
func printInfo(){
if(FBSDKAccessToken.current() != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id,name , first_name, last_name , email"]).start(completionHandler: { (connection, result, error) in
guard let Info = result as? [String: Any] else { return }
if let userName = Info["name"] as? String
{
print(userName)
}
})
}
}
}
FBSDKLoginButtonDelegate
/**
@protocol
A delegate for `FBSDKLoginButton`
*/
@protocol FBSDKLoginButtonDelegate <NSObject>
@required
/**
Sent to the delegate when the button was used to login.
@param loginButton the sender
@param result The results of the login
@param error The error (if any) from the login
*/
- (void)loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
error:(NSError *)error;
/**
Sent to the delegate when the button was used to logout.
@param loginButton The button that was clicked.
*/
- (void)loginButtonDidLogOut:(FBSDKLoginButton *)loginButton;
@optional
/**
Sent to the delegate when the button is about to login.
@param loginButton the sender
@return YES if the login should be allowed to proceed, NO otherwise
*/
- (BOOL) loginButtonWillLogin:(FBSDKLoginButton *)loginButton;
@end
Adding protocol stubs adds just 1 function (loginButton...) which is already implemented and it seems like it doesn't recognize it.
I tried cleaning project, removing derived data, restarting but still, it keeps giving me the same error:
Type 'FBViewController' does not conform to protocol 'FBSDKLoginButtonDelegate'
Help appreciated! Thanks
So after a lot of searching I have found out an answer to this problem which is described here
I have imported Turbolinks-ios which had its own Error struct, I had to use Swift.Error in method stub -