men*_*ska 2 xcode facebook-ios-sdk swift turbolinks-ios xcode10
所以我有 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)
}
})
}
}
}
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
添加协议存根只添加了 1 个已经实现的函数 (loginButton...),它似乎无法识别它。
我尝试清理项目,删除派生数据,重新启动,但它仍然给我同样的错误:
类型 'FBViewController' 不符合协议 'FBSDKLoginButtonDelegate'
帮助表示赞赏!谢谢
因此,经过大量搜索后,我找到了此问题的答案,此处描述
我已经导入了 Turbolinks-ios,它有自己的 Error 结构,我不得不在方法存根中使用 Swift.Error -
func loginButton(_ loginButton: FBSDKLoginButton!, didCompleteWith result: FBSDKLoginManagerLoginResult!, error: Swift.Error!) {...
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
662 次 |
| 最近记录: |