用户应该如何在Windows Phone 8的应用程序坚持设置? [英] How are users supposed to persist settings in a Windows Phone 8 app?

查看:135
本文介绍了用户应该如何在Windows Phone 8的应用程序坚持设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写的Windows Phone 8应用的过程中,这样我就可以捕捉抢手的3%的市场份额,和我有一个很难在应用程序中坚持用户设置。

I'm in the process of writing a Windows Phone 8 app, so I can capture that much sought-after 3% market share, and am having a hard time persisting user settings within the application.

我第一次跑过的这个博客它越过Windows.Storage命名空间,其目的是做正是​​这种事情的基础。耶!

I first ran across this blog which goes over the basics of the Windows.Storage namespace, which is intended to do exactly this sort of thing. Yay!

不过,我想笔者从来没有真正的的自己的代码,否则他会知道,第二个你叫 ApplicationData.Current.LocalSettings ,你会得到一个 NotImplementedException 例外。 要我们去MSDNs!

However, I guess the author never actually ran his own code, as otherwise he would know that the second you call ApplicationData.Current.LocalSettings, you'd get a NotImplementedException exception. To the MSDNs we go!

那么,这使得它非常清楚,这API不是在Windows Phone 8实现我得出这一结论时说,这是API没有实现,将抛出异常,如果调用。 - 嗯,这是伟大的。

Well, this makes it pretty clear that this API is not implemented on Windows Phone 8. I came to this conclusion when it said, "This API is not implemented and will throw an exception if called." - Well that's great.

所以,也许还有一些其他类似的API。经过多一点谷歌搜索,我碰到这次来到博客。这就是所谓的Windows 8的应用程序 - 必须知道技巧!。这看起来官方!它越过种种的真的很酷寻找的持久化API,包括永久和临时存储,漫游存储等

So, maybe there's some other similar APIs. After a bit more Googling, I came across this blog. It's called "Windows 8 Apps - Must Know Tricks!". This looks official! It goes over all sorts of really cool looking persistence APIs, including permanent and transient storage, roaming storage, etc.

但你猜怎么着。 RoamingFolder RoamingSettings TemporaryFolder LocalSettings - 它没有在Windows Phone 8的实施

But guess what: RoamingFolder, RoamingSettings, TemporaryFolder, LocalSettings - None of it is implemented on Windows Phone 8.

实施没有这些有点,主要功能只是滑倒了主意?我应该创建一个本地SQL数据库存储基本的应用程序设置,或者是有一些简单的我没有找到?

Did implementing these somewhat-key features just slip their mind? Am I supposed to create a local SQL database to store basic app settings, or is there something simple I'm not finding?

推荐答案

啊哈!想通了这一点。我挖出了Windows Phone 7的API文档,和传统的API其实还是在Windows Phone上工作8个为好。

Ah ha! Figured this out. I dug up the Windows Phone 7 API docs, and the legacy APIs actually still work on Windows Phone 8 as well.

public static void Session_PersistSession(string ticket)
{
   if (IsolatedStorageSettings.ApplicationSettings.Contains("SessionTicket"))
   {
      IsolatedStorageSettings.ApplicationSettings["SessionTicket"] = ticket;
   }
   else
   {
      IsolatedStorageSettings.ApplicationSettings.Add("SessionTicket", ticket);
   }

   IsolatedStorageSettings.ApplicationSettings.Save();
}

public static string Session_LoadSession()
{
   string ticket;
   if (IsolatedStorageSettings.ApplicationSettings.TryGetValue<String>("SessionTicket", out ticket))
   {
      return ticket;
   }

   return null;
}

这篇关于用户应该如何在Windows Phone 8的应用程序坚持设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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