我在尝试通过Facebook验证我的应用时遇到问题。在Facebook表单中输入用户名和密码后,我抓到了NullReferenceException
。
我注意到只有在使用Android 6.0进行编译时才会发生这种情况。
[assembly: ExportRenderer(typeof(FirstPage), typeof(FirstPageRenderer))]
namespace Dating.Droid.Renderers
{
public class FirstPageRenderer : PageRenderer
{
public FirstPageRenderer()
{
var activity = this.Context as Activity;
if (activity != null)
{
var auth = new OAuth2Authenticator(
clientId: "MyFacebookId", // your OAuth2 client id
scope: "", // the scopes for the particular API you're accessing, delimited by "+" symbols
authorizeUrl: new Uri("https://m.facebook.com/dialog/oauth/"),
redirectUrl: new Uri("http://www.facebook.com/connect/login_success.html"));
auth.Completed += (sender, eventArgs) =>
{
if (eventArgs.IsAuthenticated)
{
// Authenticated
}
else
{
// The user cancelled
}
};
activity.StartActivity(auth.GetUI(activity));
}
}
}
}
Exception appears on auth.Completed event
Stack Trace:在D:.Dv \ Real中的Dating.Droid.Renderers.FirstPageRenderer +<> c。< .ctor> b__0_0(System.Object sender,Xamarin.Auth.AuthenticatorCompletedEventArgs eventArgs)[0x00002] \ Xamarin \ Dating \ Dating.Droid \ Renderers \ FirstPageRenderer.cs:31