问题
I've got a WP8 music app where the user can login through his mobile number or either his/her email address for the first time.
I don't the want the user to type in the login details once again when he/she logs in.
What I need is to let the user directly navigate into the app's home page if the user is already logged in, in that device?
What I meant by homepage is, I wanted to go to the main page right after the splash screen
appears? How can I manipulate the splash screen
? I mean if the user is running the app for the fist time I should take him to the registration page, if the user is already logged in should go to the main page of the app directly.
Thanks in advance.
回答1:
We can do this by these steps:
1.When user login first time, you shold save userInfo in your IsolatedStorage.
2.When user launch the app again, you can get userInfo from IsolatedStorage and check if the userInfo is existed. Add Navigating for RootFrame in App.xaml.cs.
private void InitializePhoneApplication()
{
if (phoneApplicationInitialized)
return;
RootFrame = new TransitionFrame();
RootFrame.Navigated += CompleteInitializePhoneApplication;
RootFrame.NavigationFailed += RootFrame_NavigationFailed;
RootFrame.Navigating += new NavigatingCancelEventHandler(RootFrame_Navigating);//Add Navigating
phoneApplicationInitialized = true;
}
and the RootFrame_Navigating is here, when app launched, it will navigate to Login.xaml. and we should do with userIsValid(check user is valid). If valid, we should change navigate to MainPage(our home page):
void RootFrame_Navigating(object sender, NavigatingCancelEventArgs e)
{
if (e.Uri.ToString().Contains("Login.xaml"))
{
if (userIsValid)
{
e.Cancel = true; //cancel it.
string uriString = "/MainPage.xaml";
var ur = new Uri(uriString, UriKind.Relative);
RootFrame.Dispatcher.BeginInvoke(delegate
{
this.RootFrame.Navigate(ur);
});
}
}
}
来源:https://stackoverflow.com/questions/24201141/navigate-directly-into-the-app-without-logging-in-again-windows-phone