0

我的申请共有 4 页

  • 2 在外壳中 -TabBar
  • 外面的另外两个

首次安装应用程序时,必须将用户带到Login屏幕,因为他尚未通过身份验证。如果它已经过身份验证(它有一个令牌),它就会被带到Notifications屏幕上。

我面临的问题是,即使这些检查正在工作(用户被带到正确的屏幕),当他转到Login页面时(因为这是他第一次安装应用程序,或者因为他的帐户已经关闭并且他想要打开另一个)我在通知页面(在OnAppearing ()函数中)放置的检查在页面显示的同时被触发Login

我想知道是否有人会知道可能的解决方案。

AppShell.xaml

<TabBar>
        <Tab Icon="notificacao_icone.png"
             Title="Notificações">
            <ShellContent ContentTemplate="{DataTemplate local:NotificacoesPage}" />
        </Tab>

        <Tab Icon="configuracoes_icone.png"
             Title="Configurações">
            <ShellContent ContentTemplate="{DataTemplate local:ConfiguracoesPage}" />
        </Tab>
</TabBar>

AppShell.xaml.cs

public partial class AppShell : Shell
    {
        public AppShell()
        {
            InitializeComponent();

            Routing.RegisterRoute(nameof(LoginPage), typeof(LoginPage));
            Routing.RegisterRoute(nameof(TokenPage), typeof(TokenPage));
            Routing.RegisterRoute(nameof(NotificacoesPage), typeof(NotificacoesPage));
            Routing.RegisterRoute(nameof(NotificacaoDetalhePage), typeof(NotificacaoDetalhePage));
            Routing.RegisterRoute(nameof(ConfiguracoesPage), typeof(ConfiguracoesPage));

            MainThread.BeginInvokeOnMainThread(async () =>
            {
                await Task.Delay(500);

                // Carrega configurações do banco de dados
                var _config = BdRepository.tableExists("Configuracao");

                try
                {
                    if (!_config)
                    {
                        throw new Exception();
                    }
                    else
                    {
                        var _configuracao = ConfiguracaoRepository.GetAll();

                        if (string.IsNullOrEmpty(_configuracao.cad_token))
                        {
                            throw new Exception();
                        }
                        else
                        {
                            if (_configuracao.cad_token_validado_sn == "S")
                            {
                                // Redireciona para tela de notificacoes                        
                                await Shell.Current.GoToAsync($"{nameof(NotificacoesPage)}", false);
                            }
                            else
                            {
                                // Token nao validado, redireciona para tela de Token
                                await Shell.Current.GoToAsync($"{nameof(TokenPage)}", false);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // Redireciona para o cadastro
                    await Shell.Current.GoToAsync($"{nameof(LoginPage)}", false);
                }

            });
        }
    }
4

0 回答 0