Xamarin iOS: Issue with using latest version of Facebook API

ASyedASyed USMember ✭✭
edited August 2016 in Xamarin.iOS

Hi everyone. I recently updated the facebook api for Xamarin iOS : "Xamarin.Facebook.iOS" version="4.13.1"

Latest FB login API has three parameters

public unsafe virtual void LogInWithReadPermissions (string[] permissions, UIViewController fromViewController, [BlockProxy (typeof(Trampolines.NIDLoginManagerRequestTokenHandler))] LoginManagerRequestTokenHandler handler)
I am using MVVMCross. For fb login, I tried created an instance of the view i am in, and pass it as a parameter for LogInWithReadPermissions()

MY CODE:

VIEWMODEL:
private async void DoFacebookSignIn() { try { await facebookService. Login(); DoAutoLogin(); } }

SERVICE:
`
private readonly string[] permissions = new string[] { "email", "public_profile" };

public async System.Threading.Tasks.Task LogIn()
{

LoginManager.LogInWithReadPermissionsAsync (permissions);
LoginManagerLoginResult result = await LogInWithReadPermissionsAsync();

            if (result.IsCancelled)
            {
                ServiceFactory.UserMessageService.ShowToast("Facebook login is canceled");
            }
        }

    private Task<LoginManagerLoginResult> LogInWithReadPermissionsAsync()
        {
            var tcs = new TaskCompletionSource<LoginManagerLoginResult> ();
            var vc = new FbSign();
            LoginManager.LogInWithReadPermissions (permissions,vc, //I tried passing null in place of vc
    (LoginManagerLoginResult result, NSError error) =>
            {
                if(error.IsNotNull ())
                {
                    tcs.SetException (new IosErrorException(error));
                } else 
                {
                    tcs.SetResult (result);
                }
            });

            return tcs.Task;
        }`

When i run this app is crashing without throwing exceptions. Can any one advice or help me with this issue ?

Best Answer

Answers

  • IsaacThomasIsaacThomas USMember

    My app is crashing with FB login too, but it's throwing an NSErrorException when the LoginWithReadPermissionsAsync method is called (and the facebook login completes successfully). Can you post some log data so we can see the issue better?

  • SgXam15SgXam15 INMember ✭✭

    Hi @IsaacThomas were you able to cross this hiatus?I am stuck with a similar situation wherein I am receiving AccessToken.currentaccesstoken as a null even after logging in Facebook using Sharedialog.I need accesstoken as I have to implement graph Api.Any suggestions??

  • IsaacThomasIsaacThomas USMember
    HI SgXam15, I'm not familiar with share dialog, but I retrieved AccessToken.CurrentAccessToken in the OnSuccess() method of the Facebook login interface. Assuming that you did that (because retrieving AccessToken.CurrentAccessToken means the token has been returned from a successful login, as you know), make sure you do the necessary initialization for Facebook in the FinishedLaunching method of AppDelegate.cs as shown here: http://stackoverflow.com/questions/30616511/facebook-sdk-accesstoken-currentaccesstoken-always-null-even-after-logging-in/30629229#30629229
  • rmenezesrmenezes BRMember ✭✭

    @ASyed did you solve your problem? I have the same issue in my application.

  • ASyedASyed USMember ✭✭

    @rmenezes Yes.

    You need to whitelist the Observers in info.plist

    http://stackoverflow.com/questions/39169856/xamarin-issue-with-latest-fb-api

Sign In or Register to comment.