Facebook iOS SDK version 4.8 login

gauravsoni.8161gauravsoni.8161 USUniversity
edited January 2016 in Xamarin University

I am integrating a TestApp for Facebook Login. I am using Facebook iOS SDK 4.8. Here is my Code Snippet below.

public async void LoginAsync()
    {
        var loginManager = new LoginManager();
        var loginResult = await loginManager.LogInWithReadPermissionsAsync(new[] { "public_profile" });

        if ( loginResult.Token != null)
        {
                var graphRequest = new GraphRequest("/me", null, "GET");
                var requestConnection = new GraphRequestConnection();
                requestConnection.AddRequest(graphRequest, (connection, result, error) =>
                {
                   Debug.WriteLine("Login Success");
                });
                requestConnection.Start();
        }
        else
        {
                Debug.WriteLine("Error In Login");
        }
    }

in this code var loginResult = await loginManager.LogInWithReadPermissionsAsync(new[] { "public_profile" }); asks for two argument.
the second argument is UIKit.UIViewController.
if i run the app without using second argument then my app gets crash on that line. And i don't have any idea that how i put a second argument of UIKit.UIViewController.
Can anyone please help?

Best Answer

Answers

  • rene_ruppertrene_ruppert DEXamarin Team, University, XamUProfessors Xamurai

    That's the view controller that will be used to present the login dialog. Typically, you would call LogInWithReadPermissionsAsync() from within your UIViewController subclass, for instance as a reaction to a button click. This means, you would simply pass this.

    Facebook's docs state that you should be able to pass null and it will try to figure out the controller to present from. If that does not work for you, it's possible that you are not in the context of a UIViewController.

  • gauravsoni.8161gauravsoni.8161 USUniversity

    @rene_ruppert if i pass null to the argument it occurs a NullPointerException, if u pass UIViewController as an object it does not work for me, my app gets crash. Because i am calling the method LoginAsync() in my code above as Dependency on Forms on a button click.

  • gauravsoni.8161gauravsoni.8161 USUniversity

    @rene_ruppert i found the solution i did not whitelisted Facebook Security Domains. As below

    CFBundleURLTypes


    CFBundleURLSchemes

    fbMyAppIDHere



    FacebookAppID
    MyAppIDHere
    FacebookDisplayName
    MyAppnameHere

    NSAppTransportSecurity

    NSExceptionDomains

    facebook.com

    NSIncludesSubdomains

    NSThirdPartyExceptionRequiresForwardSecrecy


    fbcdn.net

    NSIncludesSubdomains

    NSThirdPartyExceptionRequiresForwardSecrecy


    akamaihd.net

    NSIncludesSubdomains

    NSThirdPartyExceptionRequiresForwardSecrecy



    LSApplicationQueriesSchemes

    fbapi
    fb-messenger-api
    fbauth2
    fbshareextension

Sign In or Register to comment.