是否有“首次试运行”? WP7中的标志 [英] Is there a "first run" flag in WP7

查看:82
本文介绍了是否有“首次试运行”? WP7中的标志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道WP7中是否有首次运行标志或类似标志。我的应用程序从隔离存储中取出了一些东西,因此我想确定这是否是第一次。我目前正在使用if来检查指定的存储对象是否存在,但这意味着我无法以自己想要的方式处理任何内存丢失错误。

I would like to know if there is a "first run" flag or similar in WP7. My app takes some stuff out of isolated storage so I would like to determine if this is necessary first time. I am currently using an if to check if the named storage object exists but this means I can't handle any memory loss errors in the way I would like.

推荐答案

我不认为这是内置功能...但是我知道您的意思:-)我自己在开源可汗学院(适用于Windows Phone应用)。我要做的就是在iso存储中查找一个非常小的文件(我只是向其中写入一个字节)...如果不存在,这是第一次,如果存在,则该应用程序已运行了不止一次。如果您愿意,请随时查看源代码并接受我的实现:-)

I don't think there is a built in feature for this ... but I know what you mean :-) I implemented "first run" myself using iso storage in the open source khan academy for windows phone app. All I do is look in iso storage for a very small file (I just write one byte to it) ... if it's not there, it's the first time, if it is there, the app has been run more than once. Feel free to check out the source and take my implementation if you'd like :-)

    private static bool hasSeenIntro;

    /// <summary>Will return false only the first time a user ever runs this.
    /// Everytime thereafter, a placeholder file will have been written to disk
    /// and will trigger a value of true.</summary>
    public static bool HasUserSeenIntro()
    {
        if (hasSeenIntro) return true;

        using (var store = IsolatedStorageFile.GetUserStoreForApplication())
        {
            if (!store.FileExists(LandingBitFileName))
            {
                // just write a placeholder file one byte long so we know they've landed before
                using (var stream = store.OpenFile(LandingBitFileName, FileMode.Create))
                {
                    stream.Write(new byte[] { 1 }, 0, 1);
                }
                return false;
            }

            hasSeenIntro = true;
            return true;
        }
    }

这篇关于是否有“首次试运行”? WP7中的标志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆