直接从手机获取设置
本文关键字:获取 设置 手机 | 更新日期: 2023-09-27 18:22:22
如何让我的代码直接从Windows Phone中的页面设置中进行设置和获取设置?
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true)
return;
else
{
MessageBoxResult result =
MessageBox.Show("Can I use your position?",
"Location",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}
else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
else
{
MessageBoxResult result =
MessageBox.Show("Can I use your position?",
"Location",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
在这个例子中,我使用了位置设置,然后我意识到当我从应用程序中将其设置为true时,它也会将页面设置中的设置更改为打开。但当我将我的位置设置从原始Windows Phone中的页面设置更改为关闭时,但在我的应用程序中,它仍然显示为真。如何解决此问题?
试试这样的东西:
if((IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent")) && ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true))
{ return; }
else
{ MessageBoxResult result =
MessageBox.Show("This app accesses your phone's location. Is that ok?",
"Location",
MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true; }
else
{IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false; }
IsolatedStorageSettings.ApplicationSettings.Save();
}