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

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



代码:

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/

10-14 23:49