【发布时间】:2014-11-29 08:13:59
【问题描述】:
如何禁用对位置服务 API 的访问?
我确实收到了一封来自 Microsoft 开发中心的信,其中包含以下提示:
您的应用必须提供允许用户启用的应用内设置 并禁用您的应用从位置访问和使用位置 服务 API。
任何人都可以就我如何做这件事提供进一步的帮助吗?
【问题讨论】:
标签: c# windows-phone-7
如何禁用对位置服务 API 的访问?
我确实收到了一封来自 Microsoft 开发中心的信,其中包含以下提示:
您的应用必须提供允许用户启用的应用内设置 并禁用您的应用从位置访问和使用位置 服务 API。
任何人都可以就我如何做这件事提供进一步的帮助吗?
【问题讨论】:
标签: c# windows-phone-7
将此代码粘贴到 MainPage.xaml 中的 InitializeComponent(); 之后。您必须通过这一行 using System.IO.IsolatedStorage; 添加对独立存储的引用。
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
return;
}
else
{
MessageBoxResult result = MessageBox.Show("Allow this app to access your location?", "Location", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}
else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
还使用 ToggleSwitch 创建一个 Settings.xaml 页面,该页面具有以下代码:
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true)
{
locationSwitch.IsChecked = true;
}
else
{
locationSwitch.IsChecked = false;
}
}
else
{
MessageBoxResult result = MessageBox.Show("Allow this app to access your location?", "Location", MessageBoxButton.OKCancel);
if (result == MessageBoxResult.OK)
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
}
else
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
}
IsolatedStorageSettings.ApplicationSettings.Save();
}
private void locationSwitch_Checked(object sender, RoutedEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = true;
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
private void locationSwitch_Unchecked(object sender, RoutedEventArgs e)
{
if (IsolatedStorageSettings.ApplicationSettings.Contains("LocationConsent"))
{
IsolatedStorageSettings.ApplicationSettings["LocationConsent"] = false;
IsolatedStorageSettings.ApplicationSettings.Save();
}
}
在您使用位置/GPS 数据的页面上包含以下代码:
if ((bool)IsolatedStorageSettings.ApplicationSettings["LocationConsent"] == true)
{
//Do Something
}
else
{
MessageBox.Show("Please enable location services to use this feature. You can turn it on from Settings.");
}
这肯定会有所帮助。我用的一样。如果这对您也有帮助,请点赞并标记为答案:)
【讨论】:
您的应用是否使用定位服务并且您需要能够禁用它,或者您是在一般情况下询问吗?
如果是第一个,则停止收集数据并在您的应用中禁用它。如果是第二个,则进入 WPmanifest 并取消选中它
【讨论】: