gpt4 book ai didi

oauth - 尝试在使用 OAuth 展示器时展示 UINavigationController

转载 作者:行者123 更新时间:2023-12-04 21:06:04 25 4
gpt4 key购买 nike

我正在为 Xamarin PCL 集成 Facebook 登录。我关注了样本“漫画书”https://github.com/moljac/Xamarin.Auth.Samples.NugetReferences并将登录过程集成到我的应用程序中。

但是,当从 Xamarin PCL 项目调用 oauth 演示者以在 iOS 上的应用程序中显示 Facebook UI 时,我收到以下异常。我提供了下面用于调用 Facebook UI 进行登录的代码。

Error: Warning: Attempt to present UINavigationController: 0x7ffa01275a00 on Xamarin_Forms_Platform_iOS_PlatformRenderer: 0x7ffa00576b80 whose view is not in the window hierarchy!



代码:
var auth = new OAuth2Authenticator(
clientId: FacebookClientId,
scope: "email",
authorizeUrl: new Uri(FacebookAuthorizeUrl),
redirectUrl: new Uri(FacebookRedirectUri));
auth.AllowCancel = true;
auth.Completed += async (s, es) =>
{
if (es.IsAuthenticated)
{
var request = new OAuth2Request(
"GET",
new Uri("https://graph.facebook.com/me?fields=email,name,picture,cover,birthday"),
null,
es.Account);
var fbResponse = await request.GetResponseAsync();
if (fbResponse != null)
{
var fbUser = JsonValue.Parse(fbResponse.GetResponseText()); // Getting the error for System.Json double exception issue as well for OAuth v1.5.0.0 only in iOS.
if (fbUser != null)
{
LoginViewModel loginViewModel = new LoginViewModel();
if (!string.IsNullOrEmpty(fbUser["name"]))
{
loginViewModel.ProfileName = fbUser["name"];
loginViewModel.UserName = fbUser["name"];
}

LoginViewModel.SelfLoginViewModel = loginViewModel;
await this.Navigation.PushModalAsync(new MasterHome());
}
else
{
await DisplayAlert("Message", "Check your internet connection!", "OK");
}
}
else
{
await DisplayAlert("Message", "Check your internet connection!", "OK");
}
}
};
auth.Error += (s, ea) =>
{
StringBuilder sb = new StringBuilder();
sb.Append("Error= ").AppendLine($"{ea.Message}");
DisplayAlert("Authentication Error", sb.ToString(),"OK");
};

Xamarin.Auth.Presenters.OAuthLoginPresenter presenter = null;
presenter = new Xamarin.Auth.Presenters.OAuthLoginPresenter();
presenter.Login(auth);

我该如何解决这个错误?

注:相同的代码非常适用于 Android。我只在 iOS 中遇到这个问题。我正在使用 Xamarin Auth v1.5.0.0

最佳答案

通过在导航堆栈中堆叠应用程序中的页面解决了问题。

关于oauth - 尝试在使用 OAuth 展示器时展示 UINavigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45627004/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com