我想将Parse与Facebook集成在一起。为此,我需要在任何我想要的地方调用PFFVideosUtils logInInBackgroundWithReadPermissions方法。在整合它们的解析指南中,它告诉我们调用这个方法,并且Parse和Facebook账号将被链接,仅此而已。我调用它时,UIButton实例被触及里面,一切工作正常,但我想知道如何添加FBSDKLoginButton(简单的行为按钮,没有链接用户,只是验证他们到Facebook)默认图像到我的自定义按钮。如何将FBSDKLoginButton默认图像添加到自定义UIButton?
-1
A
回答
0
如果我理解正确,您正在创建自己的版本FBSDKLoginButton
,它可以与解析PFFacebookUtils
一起使用。
最近我有同样的必要性和我用下面的方法:
- 创建一个UIButton -
customUIButton
- 创建FBSDKLoginButton -
fbSDKLoginButton
- 集
fbSDKLoginButton.userInteractionEnabled = false
- 添加
fbSDKLoginButton
作为customUIButton
子视图 - 将您需要的操作添加到
customUIButton
以处理e通过Parse自己登录 - FBSDKLoginButton对用户接触将是“透明的”,但在接收到来自SDK的登录/注销通知时会自动更新。
这里是我的示例代码中斯威夫特:
import UIKit
import FBSDKLoginKit
import Parse
class CustomFBLoginButton: UIButton
{
init() {
super.init(frame: CGRectZero)
let fbSDKLoginButton = FBSDKLoginButton()
fbSDKLoginButton.userInteractionEnabled = false//so it won't respond to touches
self.addSubview(fbSDKLoginButton)
self.frame = fbSDKLoginButton.frame//FBSDKLoginButton gets automatically the right frame - so let's adjust its superview to have exactly the same frame
}
required init(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
}
class ViewController: UIViewController
{
override func viewDidLoad() {
super.viewDidLoad()
let customFBLoginButton = CustomFBLoginButton()
customFBLoginButton.addTarget(self, action: "customButtonTapped:", forControlEvents: UIControlEvents.TouchUpInside)
view.addSubview(customFBLoginButton)
}
func customButtonTapped(button: CustomFBLoginButton)
{
//handle login/logout via the Parse SDK
if PFUser.currentUser() != nil {
PFUser.logOutInBackgroundWithBlock({ (_) -> Void in
println("logged out")//the button will now refresh although I noticed a small delay 1/2 seconds
})
}
else {
PFFacebookUtils.logInInBackgroundWithReadPermissions(nil)//set the permissions you need
}
}
}
2
我发现了一个问题: 如何登录到解析(与创建PFUser使用所有舒适的解析的东西),使用FBSDKLoginbutton的设计和强大的功能。 希望这是你问的问题。 我的解决方案: 使用您的按钮FBSDKLoginButton(身份检查改变类按钮), 添加FBSDKLoginButtonDelegate到类
@IBOutlet var fbLoginButton: FBSDKLoginButton!
class ViewController: UIViewController , FBSDKLoginButtonDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.fbLoginButton.readPermissions = ["public_profile","email", "user_friends" ]
self.fbLoginButton.delegate = self
}
的Xcode会在你吠叫,因为你需要清除他又该它这样做,当登录和注销:
//login to Facebook
func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) {
if let token = result.token{
//login to Parse with token
PFFacebookUtils.logInInBackgroundWithAccessToken(token, block: { (user: PFUser?, error: NSError?) -> Void in
if error != nil {
//process error
print(error?.localizedDescription)
return
}
else
{
//here you have your PFUser
}
})
}
}
不要忘记注销指令代表:
func loginButtonDidLogOut(loginButton: FBSDKLoginButton!) {
PFUser.logOutInBackground()
}
相关问题
- 1. 将第二个图像添加到自定义UIButton
- 2. 添加自定义UIButton到子视图
- 3. 将图像添加到自定义baseadapter
- 4. 将图像添加到自定义AlertDialog
- 5. Rails和的Gravatar:添加自定义的默认图像
- 6. 如何将自定义UIButton添加到Interface Builder对象库?
- 7. 如何将自定义UIbutton添加到UIAlertView?
- 8. 如何将自定义UIButton添加到XCode中的nib文件?
- 9. 如何默认小工具添加到自定义动态栏
- 10. 自定义UIButton图像iOS
- 11. 自定义UIButton与图像
- 12. 将默认值添加到“谷歌自定义搜索”
- 13. 如何将默认图片添加到SharePoint 2010的自定义列表实例图像列
- 14. 添加自定义的UIButton到UINavigationBar的
- 15. 我想添加自定义UIButton到UITableViewCell
- 16. 如何使用Branch.io将自定义图像添加到链接?
- 17. 如何将自定义图像添加到Xcode中的UITableviewController?
- 18. android:如何将自定义图像添加到小部件?
- 19. 如何将图像添加到自定义的WiX对话框?
- 20. 如何将图像添加到自定义按钮
- 21. 将图像添加到UINavigationBar中的UIButton
- 22. 如何使用默认按钮将自定义控件添加到ActionSheet?
- 23. 如何将自定义库添加到默认解决方案模板?
- 24. 如何将默认值添加到自定义ASP.NET配置文件属性
- 25. 如何将自定义弹出操作添加到默认的Eclipse编辑器
- 26. 如何将自定义参数添加到路由中的默认操作
- 27. 用自定义图像添加新的UIButton“状态”
- 28. 如何将默认值添加到RadComboBox?
- 29. 如何将UIButton添加到UIButton中
- 30. 将视图添加到自定义ViewGroup
您只想使用Facebook登录您的应用(使用Parse)。那么您打算如何使用解析进行登录? – lamdadj22