2

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.

https://i.stack.imgur.com/O7EZ0.png

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

mentoxska
  • 135
  • 9
  • Can you please add all the FB Pods dependent versions, as appeared on the Podfile.lock file? – YanivH Nov 05 '18 at 15:37
  • - Bolts (1.9.0): - Bolts/AppLinks (= 1.9.0) - Bolts/Tasks (= 1.9.0) - Bolts/AppLinks (1.9.0): - Bolts/Tasks - Bolts/Tasks (1.9.0) - FBSDKCoreKit (4.38.1): - Bolts (~> 1.9) - FBSDKLoginKit (4.38.1): - FBSDKCoreKit – mentoxska Nov 05 '18 at 16:03
  • Did you click on the `Fix` button? What happened? – mfaani Nov 05 '18 at 17:10
  • @Honey yes,I did, it just adds the same function always - loginButton(....), which doesn't fix the problem, its like it doesn't recognize, feels like bug in xcode – mentoxska Nov 05 '18 at 18:59

3 Answers3

6

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 -

 func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Swift.Error!) {...
mentoxska
  • 135
  • 9
  • So technically the Turbolinks-ios import caused your Error to be their type and not Swift.Error? Nice catch! – YanivH Nov 06 '18 at 13:21
  • @YanivH Yes, the post I put link above helped me to realize this. It’s a pity that Xcode doesn’t tell you more sometimes. – mentoxska Nov 07 '18 at 08:59
1

For others who may have come here to have problems with a class Delegate from Cocoapod.

So the issue that was having I was adding the protocols

func photo(captured: UIImage?, currentStep: StepEnum) {

But they were always asking to repeat because the cocoapod project and my project had the same class name "StepEnum" to fix that I just had to change my class name and it was resolved.

Tiago Mendes
  • 4,572
  • 1
  • 29
  • 35
0

Try to uninstall and reinstall the pods doing the following steps:

Remove all the dependencies from your .podfile (or just comment by adding a # at the beginning of the line ) Run pod install on your project directory and waiting for uninstall all pods removed re-add the pods dependencies and run pod install again Clean your project e build again


Plus: sometimes i got similar problems that are solved simply removing the functions that are required e already implemented, and try to re-adding using the auto-complete of the Xcode.

For exemple, start typing the method, choose the right on auto-complete list(if doesn't appear use ^+Space), and press enter: sample

Romulo BM
  • 671
  • 8
  • 16
  • Tried all suggestions multiple times, still receiving same error: Protocol requires function 'loginButton(_:didCompleteWith:error:)' with type '(FBSDKLoginButton?, FBSDKLoginManagerLoginResult?, Error?) -> Void'; do you want to add a stub? – mentoxska Nov 05 '18 at 19:09