普通人应该如何在 Windows Phone 8 应用程序中保留设置? [英] How are normal people supposed to persist settings in a Windows Phone 8 app?

查看:16
本文介绍了普通人应该如何在 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 异常.我们去 MSDN!

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.

但是你猜怎么着:RoamingFolderRoamingSettingsTemporaryFolderLocalSettings - 它们都没有在 Windows 上实现电话 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天全站免登陆