在我的试用版应用程序中,我正在实施一个通知,询问用户是否愿意购买。我希望显示这条消息说每隔一次应用程序启动。
我通过在IsolatedStorage
中增加名为“launchCount”的文件的长度来记录应用程序启动的次数,如下所示:
using (StreamWriter writer = new StreamWriter(appStorage.OpenFile("launchCount", FileMode.OpenOrCreate, FileAccess.ReadWrite)))
{
writer.BaseStream.SetLength(writer.BaseStream.Length + 1);
}
要确定应用程序启动的次数,我只需在IsolatedStorage
中获取文件的长度。
但是,如何确定此变量的长度是否为2,4,6,8,10等...
我尝试将检索到的变量长度除以2,但不知道如何检查它是否为整数(整数)。
任何想法?
感谢。
答案 0 :(得分:1)
如果是这样的话:
writer.BaseStream.Length % 2 == 0
然后您可以显示该消息。如果需要,可以更改2和其他间隔。
答案 1 :(得分:0)
没有百分百肯定,但我认为以下内容比使用整个文件更有效,更清晰,更简单:
private void CheckAppLaunchStatus()
{
// Application settings
readonly IsolatedStorageSettings _settings = IsolatedStorageSettings.ApplicationSettings;
if (_settings.Contains("AppLunchTimes"))
{
value = (int) _settings["AppLunchTimes"];
if (value % 2 == 0)
Deployment.Current.Dispatcher.BeginInvoke(() => MessageBox.Show("Would you like to buy the application?", "Trial Version", MessageBoxButton.OKCancel));
_settings["AppLunchTimes"] = value++;
}
else
_settings.Add(key, 1);
}