我正在实施Facebook登录到Xamarin表单项目使用Xamarin.Auth plugin。这是ios渲染代码。Xamarin验证视图关闭问题
当我点击取消按钮或成功登录时,会调用dismissviewcontroller并关闭Web视图。
当我再次点击这个Facebook或登录按钮时,我得到的错误。
警告:试图在 上展示,其视图不在窗口层次结构中!
如果有人有一个很好的解决方案,请帮助我。
[assembly: ExportRenderer(typeof(FBLoginPage), typeof(FBLoginPageRenderer))]
namespace vidmoji.iOS
{
public class FBLoginPageRenderer : PageRenderer
{
bool IsShown;
public override void ViewDidAppear(bool animated)
{
base.ViewDidAppear(animated);
if (!IsShown)
{
IsShown = true;
var auth = new OAuth2Authenticator(
clientId: App.Instance.FBAuthSettings.ClientId,
clientSecret: App.Instance.FBAuthSettings.SecurityKey,
accessTokenUrl: new Uri(App.Instance.FBAuthSettings.AccessTokenUrl),
scope: App.Instance.FBAuthSettings.Scope,
authorizeUrl: new Uri(App.Instance.FBAuthSettings.AuthorizeUrl),
redirectUrl: new Uri(App.Instance.FBAuthSettings.RedirectUrl));
auth.Completed += (sender, eventArgs) =>
{
DismissViewController(true, null);
if (eventArgs.IsAuthenticated)
{
App.Instance.loginWithFacebook(eventArgs.Account.Properties["access_token"]);
}
else {
DismissModalViewController(true);
}
};
PresentViewController(auth.GetUI(), true, null);
}
}
}
}
非常感谢。 :) – Meteoric