Reputation: 107
I have a total of 4 pages in the application
TabBar
When installing the app for the first time, the user must be taken to the Login
screen, as he does not have yet been authenticated. If it is already authenticated (it has a token), it is taken to the Notifications
screen.
The problem I am facing is that even though these checks are working (user being taken to the correct screens), when he goes to the Login
page (either because it is his first installation of the app or because his account has already been closed and he wants to open another) a check that I put on the notifications page (in the OnAppearing ()
function) is triggered at the same time as the Login
page is shown next.
I wonder if anyone would know a possible solution.
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);
}
});
}
}
Upvotes: 0
Views: 48