斯威夫特& Facebook登录:我的UIViewController不符合FBSDKLoginButtonDelegate [英] Swift & Facebook login : my UIViewController does not conform to FBSDKLoginButtonDelegate

查看:143
本文介绍了斯威夫特& Facebook登录:我的UIViewController不符合FBSDKLoginButtonDelegate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

即使Facebook教程说不需要标题,我也会在.swift文件中通过简单的导入框架添加FBSDK功能时遇到问题。

Even if Facebook tutorial says that there is no need of an header, I had problems while adding FBSDK functionalities via simple importing framework in the .swift files.

所以,我遵循了这个教程:
http://www.brianjcoleman.com/tutorial-how-to-use-login-in-facebook-sdk-4-0-for-swift/
使用swift 6.3 SDK Facebook 4.1 SDK

So, I followed this tutorial: http://www.brianjcoleman.com/tutorial-how-to-use-login-in-facebook-sdk-4-0-for-swift/ using swift 6.3 SDK Facebook 4.1 SDK

但我有两个问题

FBLoginViewViewController does not conform to FBSDKLoginButtonDelegate

Cannot assign a value of type 'FBLoginViewViewController' to a value
of type 'FBSDKLoginButtonDelegate!'

所以我无法登录,我尝试删除import语句,没有变化,我也在appDelegate中实现了每个语句,一切都应该没问题,但仍然......

so I can't login, I tried removing the import statements, no change, I also implemented every statement in the appDelegate, everything should be ok, but still...

提前感谢

 //
//  FBLoginViewViewController.swift
//  SocialFBLogin
//
//  Created by XXXX XXXX on 18/05/15.
//  Copyright (c) 2015 XXXX XXXX. All rights reserved.
//

import UIKit

import FBSDKCoreKit
import FBSDKShareKit
import FBSDKLoginKit



//@objc(FBLoginViewViewController)
class FBLoginViewViewController: UIViewController, FBSDKLoginButtonDelegate     {



@IBOutlet weak var FBLoginPicture: UIImageView!
@IBOutlet weak var FBLoginNameLabel: UILabel!

override func viewDidLoad() {


    super.viewDidLoad()
    // Do any additional setup after loading the view.

    if (FBSDKAccessToken.currentAccessToken() != nil)
    {
        // User is already logged in, do work such as go to next view controller.
    }
    else
    {
        let loginView : FBSDKLoginButton = FBSDKLoginButton()
        self.view.addSubview(loginView)
        loginView.center = self.view.center
        loginView.readPermissions = ["public_profile", "email", "user_friends"]
        loginView.delegate = self
    }

    // Facebook Delegate Methods

    func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
        println("User Logged In")

        if ((error) != nil)
        {
            // Process error
        }
        else if result.isCancelled {
            // Handle cancellations
        }
        else {
            // If you ask for multiple permissions at once, you
            // should check if specific permissions missing
            if result.grantedPermissions.contains("email")
            {
                // Do work
            }
        }
    }

    func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
        println("User Logged Out")
    }


}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
}


推荐答案

Sir ,我刚刚解决了这个问题!你必须使你的viewController符合FBSDKLoginButtonDelegate。首先,将它添加到您的协议中:

Sir, I just solved this issue! You gotta conform your viewController to FBSDKLoginButtonDelegate. first, you add it to your protocols like this:

class MainView: UIViewController, UITableViewDataSource, UITableViewDelegate, FBSDKLoginButtonDelegate 
{
    //Your Code
}

要符合此协议,您必须实现以下两种方法:

To conform to this protocol you have to implement 2 following methods:

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
    println("User Logged In")
    if ((error) != nil)
    {
        // Process error
    }
    else if result.isCancelled {
        // Handle cancellations
    }
    else {
        // If you ask for multiple permissions at once, you
        // should check if specific permissions missing
        if result.grantedPermissions.contains("email")
        {
            // Do work
        }
    }
}

func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
    println("User Logged Out")
}

你只需复制这段代码就可以了!

You just copy this code and you'll be fine!

更新为 Swift 3

func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Error!) {
    print("User Logged In")
    if ((error) != nil)
    {
        // Process error
    }
    else if result.isCancelled {
        // Handle cancellations
    }
    else {
        // If you ask for multiple permissions at once, you
        // should check if specific permissions missing
        if result.grantedPermissions.contains("public_profile")
        {
            // Do work
        }
    }
}

func loginButtonDidLogOut(_ loginButton: FBSDKLoginButton!) {
    print("User Logged Out")
}

这篇关于斯威夫特& Facebook登录:我的UIViewController不符合FBSDKLoginButtonDelegate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆