【发布时间】:2017-02-23 20:31:17
【问题描述】:
我正在使用 Xamarin.Auth plugin 实现对 Xamarin 表单项目的 facebook 登录。这是ios渲染代码。
当我点击取消按钮或登录成功时,会调用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);
}
}
}
}
【问题讨论】:
-
非常感谢。 :)
标签: ios xamarin.ios xamarin.forms