Last active
August 29, 2015 14:07
-
-
Save Cheesebaron/660441773b7b0b3ec397 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void TryRequestWhenInUseAuthorization(this CLLocationManager locationManager) | |
{ | |
if (locationManager.RespondsToSelector(new Selector("requestWhenInUseAuthorization"))) | |
locationManager.RequestWhenInUseAuthorization(); | |
} | |
public static void TryRequestAlwaysAuthorization(this CLLocationManager locationManager) | |
{ | |
if (locationManager.RespondsToSelector(new Selector("requestAlwaysAuthorization"))) | |
locationManager.RequestAlwaysAuthorization(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<key>NSLocationWhenInUseUsageDescription</key> | |
<string>Message to the user</string> | |
or | |
<key>NSLocationAlwaysUsageDescription</key> | |
<string>Message to the user</string> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) | |
{ | |
_locationManager = new CLLocationManager(); | |
_locationManager.AuthorizationChanged += LocationManagerOnAuthorizationChanged; | |
_locationManager.TryRequestWhenInUseAuthorization(); | |
} | |
else | |
{ | |
_mapView.ShowsUserLocation = ViewModel.LocationPermission; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var locationManager = new CLLocationManager(); | |
locationManager.AuthorizationChanged += LocationManagerOnAuthorizationChanged; | |
locationManager.TryRequestWhenInUseAuthorization(); | |
// create your map etc. | |
private void LocationManagerOnAuthorizationChanged(object sender, CLAuthorizationChangedEventArgs args) | |
{ | |
if (args.Status == CLAuthorizationStatus.AuthorizedWhenInUse || | |
args.Status == CLAuthorizationStatus.AuthorizedAlways) | |
_mapView.ShowsUserLocation = true; | |
else | |
_mapView.ShowsUserLocation = false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment