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

标签 oauth xamarin.ios uinavigationcontroller xamarin.forms warnings

我正在为 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/

相关文章:

python - 如何通过 Google OAuth 安全地请求数据?

oauth - 如何在自定义非Google登录网络应用中使用GoogleAuthenticator进行tfa(两因素身份验证)

go - 服务帐户流程-2条腿的Oauth Golang

c# - 如何使用 Xamarin iOS 中的默认音频播放器播放流式音频文件

c# - 为什么其中一些 Monotouch.Dialog 单元格显示为空?

iphone - iPhone monotuch 中带有可选项目的警报 View

ios - 导航到嵌入了 UINavigationController 的 UITableViewController

ios - 为什么 UINavigationBar 变黑了?

oauth - 桥接表单例份验证和 OAUTH

ios - "Unexpectedly found nil while unwrapping an Optional value"添加导航时