尝试在使用OAuth演示者时显示UINavigationController

问题描述 投票:5回答:1

我正在整合Facebook登录Xamarin PCL。我已经按照示例“漫画书”https://github.com/moljac/Xamarin.Auth.Samples.NugetReferences并将登录过程集成到我的应用程序中。

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

错误:警告:尝试在Xamarin_Forms_Platform_iOS_PlatformRenderer:0x7ffa00576b80上显示UINavigationController:0x7ffa01275a00,其视图不在窗口层次结构中!

码:

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 xamarin.ios uinavigationcontroller xamarin.forms warnings
1个回答
2
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.