显示登录页面第一次应用程序启动 [英] Show login page first time app is launched

查看:168
本文介绍了显示登录页面第一次应用程序启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个使用Facebook API的小型应用程序。我想要做的是在第一次启动应用程序时显示我的登录/连接到Facebook页面(或只要用户未通过身份验证。

I'm working on a small app that uses the Facebook API. What I want to do is show my login/connect to Facebook page the first time the app is launched (or as long as the user has not authenticated.

我的主视图实际上是一个枢纽应用程序,但是我不想显示,只要我没有Facebook访问令牌,我也希望能够从应用程序栏访问这个登录页面(这将是一样的)作为设置页面)

My primary view is actually a pivot application but I don't want to show that as long as I don't have the Facebook acces token. I also want to be able to acces this 'login' page from the application bar (it will be the same as the settings page).

任何想法我该怎么做?

推荐答案

我建议使用自定义的UriMapper,这样就可以不用担心主页面导航到登录页面,然后管理导航堆栈。

I would recommend using a custom UriMapper. This allows you to not have to worry about your main page navigating to the login page and then having to manage the navigation stack.

您可以阅读有关此方法的详细信息这里

You can read details about this approach here.

要完成此操作,请修改WMAppManifest中的DefaultTask元素以导航到假页面

To accomplish this, modify the DefaultTask element in the WMAppManifest to navigate to a fake page

<DefaultTask Name="_default" NavigationPage="LaunchPage.xaml" /> 

然后创建一个UriMapper类

Then create a UriMapper class

    public class LoginUriMapper : UriMapperBase
{
    public override Uri MapUri(Uri uri)
    {
        if (uri.OriginalString == "/LaunchPage.xaml")
        {
            // Determine for yourself how to store login info, AppSettings (IsoStore) is a good choice)
            if (NeedsLoginInfo) 
            {
                uri = new Uri("/LoginPage.xaml", UriKind.Relative);
            }
            else
            {
                uri = new Uri("/MainPage.xaml", UriKind.Relative);
            }
        }
        return uri;
    }
}

最后,为您的应用程序设置映射器Application_Launching事件

And last, set the mapper for your application in the Application_Launching event

private void Application_Launching(object sender, LaunchingEventArgs e)
{
    RootFrame.UriMapper = new LoginUriMapper();

    // You should also handle logging in if you already have info
    // Determine for yourself how to store login info, AppSettings (IsoStore) is a good choice)
    if (NeedsLoginInfo == false)
    {
         LoginObject.Login();
    }
}

在Application_Activated事件中,如果应用程序被破坏

AND in the Application_Activated event IF the app is tombstoned

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    if (e.IsApplicationInstancePreserved == false)
    {
        RootFrame.UriMapper = new LoginUriMapper();
    }
}

这篇关于显示登录页面第一次应用程序启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆