How are normal people supposed to persist settings in a Windows Phone 8 app?

前端 未结 2 699
暖寄归人
暖寄归人 2020-12-17 09:55

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

2条回答
  •  一个人的身影
    2020-12-17 10:18

    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("SessionTicket", out ticket))
       {
          return ticket;
       }
    
       return null;
    }
    

提交回复
热议问题