所以我有一个 FBViewController 类,它应该显示一个按钮让我登录和注销(只是为了测试 FB 登录)。我将它集成到新创建的项目中并且一切正常。然后我将它重新设计到我的应用程序中,但它不起作用。不确定它是否与 swift 版本或其他...使用 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
添加协议存根仅添加 1 个已实现的功能 (loginButton...),但似乎无法识别。
我尝试清理项目,删除派生数据,重新启动,但它仍然给我同样的错误:
类型“FBViewController”不符合协议“FBSDKLoginButtonDelegate”
帮助表示赞赏!谢谢