0

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.

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).

Any idea how I can do this?

2 Answers2

1

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.

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

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

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;
    }
}

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();
    }
}

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();
    }
}
Shawn Kendrot
  • 12,425
  • 1
  • 25
  • 41
0

I believe you have two choices:

  1. Show your primary view and then in the 'loaded' handler, check to see if the user has logged in previously. If they have not, then switch to the login page. The downside is that your primary view shows for a second before switching to the login page. You could show a "checking login" marquee or something.

  2. Make your startup page a simple "loading..." page. in the 'loaded' handler for this page check to see if the user is logged in or not and then switch to the appropriate page. Downside is that the loaded page will always show for a second.

I have used the first method in a commercial app and it seemed fine.

Jon
  • 2,891
  • 2
  • 17
  • 15