Das ist, was ich tat die bisherigen Antworten Berücksichtigung (dies ist in Monotouch C# aber leicht übersetzbar Swift oder Obj-C)
Die folgenden Fragen um Erlaubnis und dann fortfahren zur Standortaktualisierung, wenn sie gewährt werden. Andernfalls wird das nächste Mal der Benutzer kommen; wenn die Ortungsdienste deaktiviert oder verweigert sind, wird es eine Meldung angezeigt, die Erlaubnis/Aktivierung mit einer Umleitung zu den Einstellungen
//Location Manager (foreground)
CLLocationManager locMgr = new CLLocationManager();
locMgr.PausesLocationUpdatesAutomatically = false;
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
locMgr.RequestWhenInUseAuthorization();
}
if (CLLocationManager.LocationServicesEnabled && CLLocationManager.Status == CLAuthorizationStatus.AuthorizedWhenInUse)
{
//set the desired accuracy, in meters
locMgr.DesiredAccuracy = 150;
locMgr.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) =>
{
Console.WriteLine(e.Locations);
};
locMgr.StartUpdatingLocation();
}
else if (!CLLocationManager.LocationServicesEnabled || CLLocationManager.Status == CLAuthorizationStatus.Denied)
{
var alert = UIAlertController.Create(NSBundle.MainBundle.LocalizedString("Location access", "Location access"), NSBundle.MainBundle.LocalizedString("Please check location", "To show your position on the map, you have to enable location services and authorize the app"), UIAlertControllerStyle.Alert);
alert.AddAction(UIAlertAction.Create("Ok", UIAlertActionStyle.Cancel, null));
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
alert.AddAction(UIAlertAction.Create(NSBundle.MainBundle.LocalizedString("Go to settings", "Go to settings"), UIAlertActionStyle.Default, delegate
{
var url = new NSUrl(UIApplication.OpenSettingsUrlString);
UIApplication.SharedApplication.OpenUrl(url);
}));
}
PresentViewController(alert, true, null);
}
das ist immer noch keine Möglichkeit, verlangen, wenn der Benutzer wählen Sie „erlauben“ oder „verweigern“, es nur einmal pro ändern App installiert – adali