The last 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. To login fb I tried to create an instance of the view I'm am in and pass it as a parameter to 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 crashes, do I need to pass view information from the Viewmodel when I call this function? How to pass an instance of a view from a view model? Can anyone help?
UPDATE
Service Error:
func LogInWithReadPermissionsAsync() line3: (LoginManager.LogInWithReadPermissions...)
without any errors. Its just a glitch. API version for Facebook: "Xamarin.Facebook.iOS" version = "4.13.1"
UPDATE Removed unused code.
source share