How do I get a UIViewConroller from a subclassed ButtonRenderer for Facebook SDK authentication?

ChrisLamont.3643ChrisLamont.3643 USUniversity ✭✭
edited March 2017 in Xamarin.Forms

/cc StackOverflow: http://stackoverflow.com/q/43131170/328397

I am using a custom renderer in XamarinForms and need to pass in a ViewController into the method below. (I'm trying to use the client flow with the Facebook SDK, not the server flow)

[assembly: ExportRenderer(typeof(FacebookLoginButton), typeof(FacebookLoginButtonRendererIos))]
namespace auth.iOS
{
public class FacebookLoginButtonRendererIos : ButtonRenderer
{
    private void HandleFacebookLoginClicked()
    { 
        //var renderer = Platform.GetRenderer();
        //if (renderer == null)
        //{
        //    renderer = RendererFactory.GetRenderer (FacebookLoginPage);
        //    Platform.SetRenderer (page, renderer);
        //}
        //var viewController = renderer.ViewController;

        if (Facebook.CoreKit.AccessToken.CurrentAccessToken == null)
        {
            var login = new Facebook.LoginKit.LoginManager();
            login.LoginBehavior = Facebook.LoginKit.LoginBehavior.Browser;


            // HELP WITH THIS LINE
            login.LogInWithReadPermissions(permissionRequest.ToArray(), WHAT_DO_I_PUT_HERE_HALP!!! , (result, error) =>
                    {
                        // Handle if something went wrong with the request
                        if (error != null)
                        {
                            //new UIAlertView("Error...", error.Description, null, "Ok", null).Show();
                            return;
                        }

                        // Handle if the user cancelled the request
                        if (result.IsCancelled)
                        {
                            //new UIAlertView("The request was cancelled", 
                            //              "If you are using a Test App Id, please, make sure that your account have an Administrator role at:\rhttps://developers.facebook.com/apps/appid/roles/", null, "OK", null).Show();
                            return;
                        }
                    });
        }
    }

Best Answer

Answers

Sign In or Register to comment.