如何禁用对位置服务API的访问?
我收到了Microsoft开发中心的一封信,其中包含以下提示:
您的应用必须提供允许用户启用的应用内设置 并禁用您的应用访问和使用位置的位置 服务API。
任何人都可以提供进一步的帮助吗?
答案 0 :(得分:3)
将此代码粘贴在MainPage.xaml中的InitializeComponent();
之后。您必须通过此行using System.IO.IsolatedStorage;
添加对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.");
}
这肯定会有所帮助。我使用相同的。如果这对你有所帮助,请做upvote并标记为答案:)
答案 1 :(得分:0)
您的应用是否使用了位置服务,并且您需要能够禁用它,或者您是否一般要求?
如果是第一个,那么就停止收集数据并在应用中禁用它。如果是第二个,那么进入WPmanifest并取消选中