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()
VIEWMODEL:
private async void DoFacebookSignIn()
{
try
{
await facebookService. Login();
DoAutoLogin();
}
}
SERVICE:
private readonly string[] permitions = new string[] { "email", "public_profile" };
public async System.Threading.Tasks.Task LogIn()
{
LoginManager.LogInWithReadPermissionsAsync (permitions);
LoginManagerLoginResult result = await LogInWithReadPermissionsAsync();
if (result.IsCancelled)
{
ServiceFactory.UserMessageService.ShowToast("Facebook login is canceled");
}
}
private Task<LoginManagerLoginResult> LogInWithReadPermissionsAsync()
{
var tcs = new TaskCompletionSource<LoginManagerLoginResult> ();
LoginManager.LogInWithReadPermissions (permitions,null, (LoginManagerLoginResult result, NSError error) =>
{
if(error.IsNotNull ())
{
tcs.SetException (new IosErrorException(error));
} else
{
tcs.SetResult (result);
}
});
return tcs.Task;
}
But its failing, Do i need to pass view info from Viewmodel, when I am calling this func? How to pass view instance from view model ? Can anyone help?
UPDATE
It's failing at the service:
func LogInWithReadPermissionsAsync()
line3: (LoginManager.LogInWithReadPermissions...)
without giving any error. Its just crashing. The Facebook API version: "Xamarin.Facebook.iOS" version="4.13.1"
UPDATE Removed unused code.