Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何将FBSDKLoginButton默认图像添加到自定义UIButton?_Ios_Objective C_Facebook_Parse Platform_Uibutton - Fatal编程技术网

Ios 如何将FBSDKLoginButton默认图像添加到自定义UIButton?

Ios 如何将FBSDKLoginButton默认图像添加到自定义UIButton?,ios,objective-c,facebook,parse-platform,uibutton,Ios,Objective C,Facebook,Parse Platform,Uibutton,我想将Parse与Facebook集成。为此,我需要在任何地方调用PFFacebookUtils logininbackgroundithreadpermissions方法。在集成它们的parse指南中,它告诉我们调用这个方法,parse和Facebook帐户将被链接,仅此而已。当一个UIButton实例在内部被修改并且一切正常时,我会调用它,但我想知道如何添加FBSDKLoginButton(一个简单的行为按钮,不需要链接用户,只需将用户验证到Facebook)默认图像到我的自定义按钮。如果我

我想将Parse与Facebook集成。为此,我需要在任何地方调用PFFacebookUtils logininbackgroundithreadpermissions方法。在集成它们的parse指南中,它告诉我们调用这个方法,parse和Facebook帐户将被链接,仅此而已。当一个UIButton实例在内部被修改并且一切正常时,我会调用它,但我想知道如何添加FBSDKLoginButton(一个简单的行为按钮,不需要链接用户,只需将用户验证到Facebook)默认图像到我的自定义按钮。

如果我理解正确,您正在创建自己版本的
FBSDKLoginButton
,该按钮可以与Parse
PFFacebookUtils
一起使用

我最近也有同样的需要,我采用了以下方法:

  • 创建UIButton-
    customUIButton
  • 创建FBSDKLoginButton-
    FBSDKLoginButton
  • Set
    fbSDKLoginButton.userInteractionEnabled=false
  • 添加
    fbSDKLoginButton
    作为
    customUIButton
  • 将您需要的操作添加到
    customUIButton
    以通过解析自己处理登录-FBSDKLoginButton对用户触摸是“透明”的,但在收到SDK的登录/注销通知时会自动更新
  • 以下是我在Swift中的示例代码:

    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
            }
        }
    }
    
    我发现了一个问题: 如何使用FBSDKLoginbutton设计和强大的功能登录解析(创建PFUser以使用所有舒适的解析内容)。 希望这是你问的问题。 我的解决方案: 将您的按钮用作FBSDKLoginButton(在identity inspector中更改按钮的类别), 将FBSDKloginButtonLegate添加到类中

            @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()
    }
    

    你只想使用Facebook登录你的应用程序(使用Parse)。那么,您打算如何使用parse登录?