我关注了tutorial在这里将 Facebook 登录集成到我的应用程序中。我可以使用该按钮成功登录,但它不会在登录时调用我的方法 didCompleteWithResult
来获取用户详细信息。这是我的代码。
import UIKit
class LoginViewController: UIViewController, FBSDKLoginButtonDelegate {
@IBOutlet weak var loginBtn: FBSDKLoginButton!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func configureFacebook()
{
loginBtn.readPermissions = ["public_profile", "email", "user_friends"];
loginBtn.delegate = self
}
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!){
FBSDKGraphRequest.init(graphPath: "me", parameters: ["fields":"first_name, last_name, picture.type(large)"]).startWithCompletionHandler { (connection, result, error) -> Void in
let strFirstName: String = (result.objectForKey("first_name") as? String)!
let strLastName: String = (result.objectForKey("last_name") as? String)!
let strPictureURL: String = (result.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as? String)!
print("Welcome, \(strFirstName) \(strLastName)")
//self.profilePic.image = UIImage(data: NSData(contentsOfURL: NSURL(string: strPictureURL)!)!)
}
}
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!)
{
}
}
最佳答案
选项1
我不知道你在哪里添加这个方法在这里我动态提交答案,自定义你自己..
override func viewDidLoad() {
super.viewDidLoad()
configureFacebook() // if you want here add here or else if you want to load the facebook details in Button action add there
// Do any additional setup after loading the view.
}
func configureFacebook()
{
loginBtn.readPermissions = ["public_profile", "email", "user_friends"];
loginBtn.delegate = self
}
选项2
如果您直接在 View Controller 中添加委托(delegate),请执行以下操作
关于ios - 不调用 Facebook loginButton didCompleteWithResult,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34986264/