2013-05-07 76 views
2

如何可以訪問到位置服務API禁止訪問被禁止?到位置服務API

我沒有收到來自微軟開發中心一封信,信中包含此提示:

您的應用程序必須提供應用程序內設置,允許用戶啓用 和禁用和使用位置的應用程序的訪問從位置 服務API。

任何人都可以提供我如何去這樣做進一步的幫助?

回答

0

請問您的應用程序使用位置服務,你需要有禁用它的能力,或者你在一般要求?

如果它是第一個然後就停止收集數據,並在您的應用程序禁用它。如果是第二個,然後進入WPmanifest和MainPage.xaml中InitializeComponent();後立即取消其

3

粘貼此代碼。您必須按此行添加對IsolatedStorage的引用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."); 
} 

這必將幫助。我使用相同的。不要給予好評,並標記爲答案,如果這可以幫助您太:)