Xamarin Facebook iOS app: Unable to login with Facebook Application (browser works)
Using Xamarin.Facebook.iOS version 4.40.0, logging in with the Facebook app doesn't work. When the app switches back to my application, the token is null and result.IsCancelled is true.
Using LoginBehavior Web is the only method that works. When using the app, result.IsCancelled is true.
Any clue why the latest Xamarin.Facebook.iOS SDK isn't working? Code below:
var manager = new LoginManager(); manager.LoginBehavior = LoginBehavior.SystemAccount; manager.LogInWithReadPermissions(new string[] { "public_profile", "email" }, vc, (result, error) => { if (error != null || result == null || result.IsCancelled) { if (error != null) { OnLoginComplete?.Invoke(null, error.LocalizedDescription); } if (result.IsCancelled) { OnLoginComplete?.Invoke(null, "User Cancelled!"); } tcs.TrySetResult(null); }
Hi @kwacks
I'm currently on 4.35.0, did it stop working after an update?
My code is very simliar. the only difference is I have a call to manager.LogOut()
var window = UIApplication.SharedApplication.KeyWindow;
var vc = window.RootViewController;
while (vc.PresentedViewController != null)
{
vc = vc.PresentedViewController;
}
var manager = new LoginManager();
manager.LogOut(); // <-- HERE
manager.LoginBehavior = LoginBehavior.SystemAccount;
manager.LogInWithReadPermissions(new string[] { "public_profile", "email" },
...
Also, be sure to have your info.plist properly populated as defined in https://developers.facebook.com/docs/facebook-login/ios/
Hope that helps.
@kwacks are you still facing this issue?
Yes, I am with v4.40. I have the exact same code as @AntRemo but result.IsCancelled is true when i authorize through the facebook app.
I just updated to 5.0.2 and noticed that the only LoginBehavior is "Browser". This launches the browser which has the option to login with the app or using email/phone number. The email/phone number option in the browser works. The app option doesn't work for me it just returns back to that page in the browser and doesn't even pop back to my app.
I've also found that the LoginBehavior enum only has one value, Browser, in version 5.0.2. LoginBehavior.Native is no longer available. Also, the LoginButton class no longer has a ReadPermissions property.
Are LoginBehavior.Native and ReadPermissions no longer necessary? According to this link they are still required: https://github.com/xamarin/FacebookComponents/blob/master/Facebook.iOS/docs/LoginKit/Details.md
@kwacks Please, make sure that you have implemented some AppDelegate methods as showed here. If that doesn't work, can you provide a test case?
@ashleypringle FB now handles the Login only via Browser and also the ReadPermissions and PublishPermissions were merged into Permissions property. We are planning to update and provide a more complete Getting Started guide.
Hope this helps.
@SotoiGhost Great, thank you for the info!
@SotoiGhost Oh my that was it - I didn't have the OpenUrl override in my app delegate to handle this. It works well now. Sorry this was my oversight. Thanks very much for your help.
@SotoiGhost do you have any update documentation? The "Permissions" is not defined as well as "LogInWithReadPermissions"
My code errors at LogInWithReadPermissions:
var manager = new LoginManager();
var vc = UIApplication.SharedApplication.KeyWindow.RootViewController;
while (vc.PresentedViewController != null)
vc = vc.PresentedViewController;
manager.LoginBehavior = LoginBehavior.Browser;
manager.LogInWithReadPermissions(Permissions, vc, (result, error) =>...
I found the answer to my question. This line of code fixes my build error: manager.LogIn(Permissions, vc, (result, error) =>...
@traceyhemp12 how are you using accessing token here ?
Does this help @NehaGawri .....
var token = AccessToken.CurrentAccessToken.TokenString;
var permissions = new List<string>();
foreach (var permission in AccessToken.CurrentAccessToken.Permissions)
permissions.Add(permission.ToString());
OnReceivedAccessToken(token, permissions);