This is what I did based on previous answers: (this is in MonoTouch C #, but easily translatable to Swift or Obj-C)
The next one requests permission and then proceeds to update the location, if one is provided. Otherwise, the next time the user comes; if location services are disabled or rejected, a message will be displayed asking for permission / activation with a redirect to the settings
//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); }
source share