Facebook login init

Hi everybody!
How can I initiate a Facebook login process when I handle my own button? I use Xamarin.Facebook.iOS nuget pack (v. 4.5.1).

For instance, I have a ButtonRenderer class, where I handle users touchUp the button, and somewhere here I need to put some Facebook code, which opens FB login page in web-browser and so on:

    public class LoginButtonRenderer : ButtonRenderer
        {
            protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
            {
                UIButton me;
                base.OnElementChanged(e);

                if (Control != null)
                {
                    me = Control;
                    me.TouchUpInside += OnTouchUpInside;
                }
            }

        private void OnTouchUpInside(object sender, EventArgs e)
        {
            // what should I write here?
        }
    }

Posts

  • EgeAydinEgeAydin TRMember

    first create a LoginButton instance, then call Send ActionForControlEvents.

    public class LoginButtonRenderer : ButtonRenderer
    {

        List<string> readPermissions = new List<string> { "public_profile", "email", "user_friends" };
        Facebook.Corekit.Button.LoginButton fbButton;
    
            protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
            {
                UIButton me = Facebook.Corekit.Button.LoginButton{
                LoginBehavior = LoginBehavior.Native,
                ReadPermissions = readPermissions.ToArray ()
        };
                base.OnElementChanged(e);
        fbButton = new 
                if (Control != null)
                {
                    me = Control;
                    me.TouchUpInside += OnTouchUpInside;
                }
        fbButton.Completed += OnLoginComplete;
            }
    
        private void OnTouchUpInside(object sender, EventArgs e)
        {
    
        fbButton.SendActionForControlEvents(UIControlEvent.TouchUpInside);
        }
    
    private void OnLoginComplete(object sender, EventArgs e)
    {
        //Do whatever you want after login complete
    }
    }
    
  • matteraimatterai USMember

    Thanks, it was amazingly simple! =)

  • EgeAydinEgeAydin TRMember

    Well some of what I written is wrong and I cannot edit it since 1 hour is passed. But I see that you have done it anyways. Glad to help.

Sign In or Register to comment.