我第一次尝试在 iOS 应用程序上使用 Facebook API。我正在尝试实现一个登录按钮,就像 facebook API 文档中所说的那样。
这是我的应用委托(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)
}
这是我的 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")
}
我收到此错误“ViewController”类型不符合协议(protocol)“FBSDKLoginButtonDelegate”
在线 class ViewController: UIViewController, FBSDKLoginButtonDelegate
而我在网上找到的一个项目使用完全相同的语法,没有出现错误,项目构建也没有任何问题。
有没有人遇到同样的问题?
最佳答案
尝试实现 FBSDKLoginButtonDelegate 所需的方法。
关于ios - 类型 'ViewController' 不符合协议(protocol) 'FBSDKLoginButtonDelegate',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33038804/