Detect app first launch windows phone [duplicate]

2019-09-07 10:48发布

This question already has an answer here:

I'm quite new on windows phone dev. I would like to detect when the user launches my app for the first time to display an explaination frame for example by calling :

if(firstLaunch)
showTheFrameToTheGuyBecauseHeLaunchedTheAppForTheFirstTime();

I would be sooooooo glad if someone could show us such a small script...

Thank you in advance guys !

2条回答
霸刀☆藐视天下
2楼-- · 2019-09-07 11:31

I would recommend you to use the builtin applicationsettings.

const string settingsAppLaunched = "appLaunched";

public static bool IsFirstLaunch(){
    IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
    return !(settings.Contains(settingsAppLaunched) && settings[settingsAppLaunched]);
}

public static bool Launched(){
    if(IsFirstLaunch()){
        IsolatedStorageSettings settings = IsolatedStorageSettings.ApplicationSettings;
        settings.Add(settingsAppLaunched, true);
        settings.Save();
    }
}

//usage:
if(IsFirstLaunch()){
    showTheFrameToTheGuyBecauseHeLaunchedTheAppForTheFirstTime();
    Launched();
} 

Microsoft Documentation about Settings in Windows Phone is available here.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-09-07 11:45

You can simply use IsolatedStorageSettings.

if(!IsolatedStorageSettings.ApplicationSettings.Contains("first"))
{
   // Do your stuff
   IsolatedStorageSettings.ApplicationSettings["first"] = true;
   IsolatedStorageSettings.ApplicationSettings.Save();
}

This code will do it.

查看更多
登录 后发表回答