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

查看:19
本文介绍了是否有“第一次运行"?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.

推荐答案

我不认为有针对此的内置功能......但我知道你的意思:-) 我自己实现了首次运行"开源 khan academy for windows phone 应用程序 中的 iso 存储.我所做的只是在 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天全站免登陆