2014-06-07 4 views
0

몇 달 전에 Windows Phone 앱을 만들었는데 이제 Windows 스토어에서도 사용하려고합니다. 최고 기록을 저장하는 것 외에는 모든 것이 작동합니다. 나는 API를 통해 독서를 시도했지만 단지 어떤 이유로 그것을 얻을 수없는 것.Windows Store 앱에 최고 기록을 저장 하시겠습니까?

다음 Windows Phone 코드가 Windows Store 앱에 대해 어떻게 표시되어야하는지 알려주시겠습니까? 나는 그 밖의 모든 것을 고려해 볼 때 거의 같을 것이라고 기대했다. 감사.

윈도우 스토어 앱에서
private IsolatedStorageSettings appsettings = IsolatedStorageSettings.ApplicationSettings; 

private void SetHighScore() 
    { 
     if (appsettings.Contains("highscore")) 
     { 
      int high = Convert.ToInt32(appsettings["highscore"]); 

      if (score > high) //if the current score is greater than the high score, make it the new high score 
      { 
       appsettings.Remove("highscore"); 
       appsettings.Add("highscore", score); 

       GoogleAnalytics.EasyTracker.GetTracker().SendEvent("mainpage", "highscore " + score.ToString(), null, score); 
      } 

      else //if the current score if less than or equal to the high score, do nothing 
      { 
       //do nothing 
      } 
     } 

     else 
     { 
      appsettings.Add("highscore", score); //if there is no high score already set, set it to the current score 
     } 
    } 

    private void GetHighScore() 
    { 
     if (appsettings.Contains("highscore")) //if there is a highscore display it 
     { 
      int high = Convert.ToInt32(appsettings["highscore"]); 
      txbHighScore.Text = high.ToString(); 
     } 

     else //if there is no highscore display zero 
     { 
      txbHighScore.Text = "0"; 
     } 
    } 

답변

2

, 당신은 데이터를 저장하고 얻을 LocalSettings 또는 RoamingSettings를 사용할 수 있습니다. LocalSettings는 하나의 기기에 데이터를 저장하고 RoamingSettings는 동일한 계정으로 기기의 데이터를 동기화합니다. 이것은 LocalSettings의 샘플 코드이며 RoamingSettings는 유사합니다.

public class LocalSettingsHelper 
{ 
    public static void Save<T>(string key, T value) 
    { 
     ApplicationData.Current.LocalSettings.Values[key] = value; 
    } 

    public static T Read<T>(string key) 
    { 
     if (ApplicationData.Current.LocalSettings.Values.ContainsKey(key)) 
     { 
      return (T)ApplicationData.Current.LocalSettings.Values[key]; 
     } 
     else 
     { 
      return default(T); 
     } 
    } 

    public static bool Remove(string key) 
    { 
     return ApplicationData.Current.LocalSettings.Values.Remove(key); 
    } 
} 
관련 문제