首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >查马林自视近况问题

查马林自视近况问题
EN

Stack Overflow用户
提问于 2017-02-23 20:31:17
回答 1查看 463关注 0票数 0

我正在使用Xamarin.Auth插件实现Xamarin的facebook登录。这是ios呈现代码。

当我单击“取消”按钮或成功登录时,会调用“拒绝”视图并关闭web视图。

当我再次点击这个facebook或登录按钮时,我会出现以下错误。

警告:尝试显示其视图不在窗口层次结构中!

如果有人有很好的解决办法,请帮帮我。

代码语言:javascript
复制
[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);
            }
        }
    }
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-24 00:02:17

更新应答

在FBLoginPage中添加一个公共方法。

代码语言:javascript
复制
public partial class FBLoginPage : ContentPage
{
    //......

    public void OnAuthenticationCompleted (bool isAuthenticated, string accessToken)
    {
        //Get your token and do what you need to do with it.
        Navigation.PopModalAsync (true);
    }
}

您的呈现类将其更改为:

代码语言:javascript
复制
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) => {

            var element = Element as LoginPage;

            var token = eventArgs.IsAuthenticated ? eventArgs.Account.Properties ["access_token"] : null;

            element?.OnAuthenticationCompleted (eventArgs.IsAuthenticated, token);
        };

        PresentViewController (auth.GetUI (), true, null);
    }

}

关于最新情况。

这个组件从两年前就没有更新过,但是nuget包装已经更新了。我建议从组件改为Nuget包。

祝好运。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42425627

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档