首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Xamarin.Auth Facebook给出NullReferenceException 2

Xamarin.Auth Facebook给出NullReferenceException 2
EN

Stack Overflow用户
提问于 2017-09-10 03:22:41
回答 1查看 633关注 0票数 5

我正在跟踪这一页和一些来自Xamarin.Auth github的示例,所以设置一个facebook登录。我创建了以下登录函数:

代码语言:javascript
复制
public void Authenticate()
{
    string clientId = Config.FacebookAppID;
    string redirectUri = redirectUri = "MyApp:/authorize";
    var authenticator = new OAuth2Authenticator(
        clientId: clientId,
        scope: "public_profile,email",
        authorizeUrl: new Uri("https://www.facebook.com/v2.9/dialog/oauth"),
        redirectUrl: new Uri(redirectUri),
        getUsernameAsync: null,
        isUsingNativeUI: true);

    authenticator.AllowCancel = true;
    authenticator.Completed += OnAuthCompleted;
    authenticator.Error += OnAuthError;
    Authenticator = authenticator;

    var presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
    presenter.Login(Authenticator);
}

但是,在最后一行中,我得到了以下例外:

代码语言:javascript
复制
{System.NullReferenceException: Object reference not set to an instance of an object.
  at Xamarin.Auth.Presenters.OAuthLoginPresenter.Login (Xamarin.Auth.Authenticator authenticator) [0x00011] in C:\cxa\source\Xamarin.Auth.LinkSource\Request.cs:290 
  at MyApp.Components.AuthorisationManager.Authenticate () [0x00078] in D:\Dev\MenuSystem.AdminApp\MyApp\MyApp\MyApp\Components\AuthorisationManager.cs:56 
  at MyApp.ViewModels.MainPageViewModel.NavigateToMenuItem () [0x00008] in D:\Dev\MenuSystem.AdminApp\MyApp\MyApp\MyApp\ViewModels\MainPageViewModel.cs:63 }

你知道我做错了什么吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-05 23:44:04

我知道这已经有一年多的历史了,然而,在一次有指导的链接式训练之后,我遇到了同样的问题。

答案是在AuthenticationConfiguration类中的FinishedLaunching方法中初始化AppDelegate

代码语言:javascript
复制
public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
{
    // Override point for customization after application launch.
    // If not required for your application you can safely delete this method
    // Add the Init() method here
    global::Xamarin.Auth.Presenters.XamarinIOS.AuthenticationConfiguration.Init();
    return true;
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46136998

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档