gpt4 book ai didi

xcode - 带有 FBSDKLoginButton 图像的自定义按钮

转载 作者:行者123 更新时间:2023-11-30 13:33:43 24 4
gpt4 key购买 nike

我想使用带有图像的自定义按钮,

我不想使用 Facebook 默认登录按钮。

这是我的代码

    let loginButton = FBSDKLoginButton()
loginButton.readPermissions = ["public_profile", "email", "user_friends"]
loginButton.center = self.view.center
loginButton.delegate = self
loginButton.imageView?.image = UIImage(named: "cyanx2")
self.view.addSubview(loginButton)

我的按钮是

@IBAction func customButton(sender: UIButton) {

// here's go the action when click on default facebook button
}

最佳答案

根据this发布

我解决了我的问题^_^,这是代码

按钮功能

@IBAction func loginFacebookAction(sender: AnyObject) {
let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
fbLoginManager.logInWithReadPermissions(["email"], fromViewController: self) { (result, error) -> Void in

if error != nil {
NSLog("Process error")
}
else if result.isCancelled {
NSLog("Cancelled")
}
else {
NSLog("Logged in")
self.getFBUserData()
}

}
}

从 facebook 获取结果的函数

 func getFBUserData(){
if((FBSDKAccessToken.currentAccessToken()) != nil){
FBSDKGraphRequest(graphPath: "me", parameters: ["fields": "id, name, first_name, last_name, picture.type(large), email"]).startWithCompletionHandler({ (connection, result, error) -> Void in
if (error == nil){
//everything works print the user data
print(result)
}
})
}
}

关于xcode - 带有 FBSDKLoginButton 图像的自定义按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36318901/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com