Vincent Monteil Vincent Monteil - 5 months ago 19
Swift Question

The type 'ViewController' does not conform to protocol 'FBSDKLoginButtonDelegate'

I am trying to use Facebook API for the 1st time on an iOS App. I'm trying to implement a login button like told on facebook API doc.

Here is my app delegate :

import UIKit
import FBSDKCoreKit

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?


func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
//return true
return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool
{
return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}


Here is my view controller:

import UIKit
import FBSDKCoreKit
import FBSDKLoginKit

class ViewController: UIViewController, FBSDKLoginButtonDelegate
{


// @IBOutlet weak var testLabel: UILabel!

override func viewDidLoad() {
super.viewDidLoad()

if (FBSDKAccessToken.currentAccessToken() == nil)
{
NSLog("Not logged in..")
}
else
{
NSLog("Logged in..")
}

//Création et positionnement du bouton de login Facebook
let loginButton:FBSDKLoginButton=FBSDKLoginButton()
loginButton.center=self.view.center
self.view.addSubview(loginButton)
loginButton.delegate=self
loginButton.readPermissions=["public_profile", "email", "user_fiends"]
NSLog("UI OK")
}


I am getting this error
The type 'ViewController' does not conform to protocol 'FBSDKLoginButtonDelegate'

on the line
class ViewController: UIViewController, FBSDKLoginButtonDelegate


Whereas on a project that I found on the web using exactly the same syntax, no error comes up and the project builds without any problem.

Did anyone of you have the same problem ?

Answer

in the new Xcode/iOS developing format is e if we use or declared any delegate's compulsory declare the method also, just like FBSDKLoginButtonDelegate we need to implement the delegate methods, else remove the delegate in Header

- (void)  loginButton:  (FBSDKLoginButton *)loginButton
didCompleteWithResult:  (FBSDKLoginManagerLoginResult *)result
                error:  (NSError *)error{

    NSLog(@"facebook login button test");


}
Comments