1

I am developing a windows 7 phone app where I want a particular page( A privacy policy which the user needs to accept ) to be displayed when the user uses the app for the first time in his phone. Can any one please tell me how to get this done.

2 Answers2

0

A possible answer to this question can be found here. As you want your page to open up only once I suggest IsolatedStorageSettings to save a boolean value if the user has accepted the policy or not.

Community
  • 1
  • 1
xmashallax
  • 1,495
  • 1
  • 16
  • 32
0

Two approaches can be taken for this functionality. The first is to always start at the privacy policy page but override the OnNavigatedTo method to check if the policy has been accepted before. If it has, navigate to your "MainPage". Within the Mainpage, remove all backstack entries.

Privacy Policy Page

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    // have the accepted the policy?
    var settings = IsolatedStorageSettings.ApplicationSettings;
    bool accepted;
    if(settings.TryGetValue("PolicyAccepted", out accepted))
    {
        if (accepted)
        {
            NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
        }
    }
}

private void OnAcceptButtonClick(object sender, RoutedEventArgs routedEventArgs)
{
    var settings = IsolatedStorageSettings.ApplicationSettings;
    settings["PolicyAccepted"] = true;
    settings.Save();
    NavigationService.Navigate(new Uri("MainPage.xaml", UriKind.Relative));
}

Then in your MainPage, remove the backstack

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    while (NavigationService.CanGoBack) NavigationService.RemoveBackEntry();
}

The second approach is to is a UriMapper as described in this SO answer.

Community
  • 1
  • 1
Shawn Kendrot
  • 12,170
  • 1
  • 19
  • 39
  • Thanks for your idea @ShawnKendrot. It worked well. Executing the app again is giving me the privacy policy for the first time. But this is similar to installing the app again in the phone. So we get privacy policy again for the first time. Is my understanding correct ? – user2736177 Oct 31 '13 at 06:46
  • With this approach, you should only get the policy page the first time you (re)install the app. If you want it to only ask once, regardless of how many times the app is installed, you will need to store the acceptance in a server – Shawn Kendrot Oct 31 '13 at 17:05