本文整理汇总了C#中CLLocationManager.RequestWhenInUseAuthorization方法的典型用法代码示例。如果您正苦于以下问题:C# CLLocationManager.RequestWhenInUseAuthorization方法的具体用法?C# CLLocationManager.RequestWhenInUseAuthorization怎么用?C# CLLocationManager.RequestWhenInUseAuthorization使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CLLocationManager
的用法示例。
在下文中一共展示了CLLocationManager.RequestWhenInUseAuthorization方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FinishedLaunching
public override void FinishedLaunching(UIApplication application)
{
locationManager = new CLLocationManager ();
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
locationManager.RequestWhenInUseAuthorization ();
}
// A user can transition in or out of a region while the application is not running.
// When this happens CoreLocation will launch the application momentarily, call this delegate method
// and we will let the user know via a local notification.
locationManager.DidDetermineState += (sender, e) => {
string body = null;
if (e.State == CLRegionState.Inside)
body = "You're inside the region";
else if (e.State == CLRegionState.Outside)
body = "You're outside the region";
if (body != null) {
var notification = new UILocalNotification () { AlertBody = body };
// If the application is in the foreground, it will get called back to ReceivedLocalNotification
// If its not, iOS will display the notification to the user.
UIApplication.SharedApplication.PresentLocalNotificationNow (notification);
}
};
}
示例2: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad ();
locMan = new CLLocationManager();
locMan.RequestWhenInUseAuthorization();
locMan.RequestAlwaysAuthorization();
// Geocode a city to get a CLCircularRegion,
// and then use our location manager to set up a geofence
button.TouchUpInside += (o, e) => {
// clean up monitoring of old region so they don't pile up
if(region != null)
{
locMan.StopMonitoring(region);
}
// Geocode city location to create a CLCircularRegion - what we need for geofencing!
var taskCoding = geocoder.GeocodeAddressAsync ("Cupertino");
taskCoding.ContinueWith ((addresses) => {
CLPlacemark placemark = addresses.Result [0];
region = (CLCircularRegion)placemark.Region;
locMan.StartMonitoring(region);
});
};
// This gets called even when the app is in the background - try it!
locMan.RegionEntered += (sender, e) => {
Console.WriteLine("You've entered the region");
};
locMan.RegionLeft += (sender, e) => {
Console.WriteLine("You've left the region");
};
}
示例3: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
// Perform any additional setup after loading the view, typically from a nib.
ConfigureView();
_iPhoneLocationManager = new CLLocationManager();
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
_iPhoneLocationManager.RequestWhenInUseAuthorization();
}
mapView.ShowsUserLocation = true;
if (mapView.UserLocationVisible)
{
UpdateUiCoords();
}
_iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer
mapView.DidUpdateUserLocation += (sender, e) =>
{
if (mapView.UserLocation != null)
{
CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate;
MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude));
mapView.Region = new MKCoordinateRegion(coords, span);
UpdateUiCoords();
}
};
}
示例4: Start
public void Start ()
{
if (CLLocationManager.LocationServicesEnabled) {
lman = new CLLocationManager {
DesiredAccuracy = CLLocation.AccuracyBest,
};
lman.RequestWhenInUseAuthorization ();
lman.LocationsUpdated += (sender, e) => {
var loc = e.Locations [0];
Timestamp = loc.Timestamp;
Location = new Location (loc.Coordinate.Latitude, loc.Coordinate.Longitude, loc.Altitude);
// Console.WriteLine (Location);
HorizontalAccuracy = loc.HorizontalAccuracy;
VerticalAccuracy = loc.VerticalAccuracy;
LocationReceived (this, EventArgs.Empty);
};
lman.UpdatedHeading += (sender, e) => {
Heading = e.NewHeading.TrueHeading;
// Console.WriteLine ("Heading: {0}", Heading);
};
lman.StartUpdatingLocation ();
lman.StartUpdatingHeading ();
}
}
示例5: EnableLocationServices
public void EnableLocationServices()
{
manager = new CLLocationManager();
manager.AuthorizationChanged += (sender, args) => {
Console.WriteLine ("Authorization changed to: {0}", args.Status);
};
if (UIDevice.CurrentDevice.CheckSystemVersion(8,0))
manager.RequestWhenInUseAuthorization();
}
示例6: ViewDidLoad
public override void ViewDidLoad ()
{
// all your base
base.ViewDidLoad ();
// load the appropriate view, based on the device type
this.LoadViewForDevice ();
// initialize our location manager and callback handler
iPhoneLocationManager = new CLLocationManager ();
// uncomment this if you want to use the delegate pattern:
//locationDelegate = new LocationDelegate (mainScreen);
//iPhoneLocationManager.Delegate = locationDelegate;
// you can set the update threshold and accuracy if you want:
//iPhoneLocationManager.DistanceFilter = 10; // move ten meters before updating
//iPhoneLocationManager.HeadingFilter = 3; // move 3 degrees before updating
// you can also set the desired accuracy:
iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer
// you can also use presets, which simply evalute to a double value:
//iPhoneLocationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;
// handle the updated location method and update the UI
if (UIDevice.CurrentDevice.CheckSystemVersion (6, 0)) {
iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
UpdateLocation (mainScreen, e.Locations [e.Locations.Length - 1]);
};
} else {
#pragma warning disable 618
// this won't be called on iOS 6 (deprecated)
iPhoneLocationManager.UpdatedLocation += (object sender, CLLocationUpdatedEventArgs e) => {
UpdateLocation (mainScreen, e.NewLocation);
};
#pragma warning restore 618
}
//iOS 8 requires you to manually request authorization now - Note the Info.plist file has a new key called requestWhenInUseAuthorization added to.
if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
{
iPhoneLocationManager.RequestWhenInUseAuthorization();
}
// handle the updated heading method and update the UI
iPhoneLocationManager.UpdatedHeading += (object sender, CLHeadingUpdatedEventArgs e) => {
mainScreen.LblMagneticHeading.Text = e.NewHeading.MagneticHeading.ToString () + "º";
mainScreen.LblTrueHeading.Text = e.NewHeading.TrueHeading.ToString () + "º";
};
// start updating our location, et. al.
if (CLLocationManager.LocationServicesEnabled)
iPhoneLocationManager.StartUpdatingLocation ();
if (CLLocationManager.HeadingAvailable)
iPhoneLocationManager.StartUpdatingHeading ();
}
示例7: RangingVC
public RangingVC (IntPtr handle) : base (handle)
{
SetUpHue ();
//set up sqlite db
var documents = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
_pathToDatabase = Path.Combine (documents, "db_sqlite-net.db");
region = new CLBeaconRegion (AppDelegate.BeaconUUID, "BeaconSample");//ushort.Parse ("26547"), ushort.Parse ("56644"),
region.NotifyOnEntry = true;
region.NotifyOnExit = true;
locationManager = new CLLocationManager ();
locationManager.RequestWhenInUseAuthorization ();
locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
if (e.Beacons.Length > 0) {
CLBeacon beacon = e.Beacons [0];
switch (beacon.Proximity) {
case CLProximity.Immediate:
SetImmediateColor();
message = "Immediate";
break;
case CLProximity.Near:
message = "Near";
SetNearColor();
break;
case CLProximity.Far:
message = "Far";
SetFarColor();
break;
case CLProximity.Unknown:
message = "Unknown";
SetUnknownColor();
break;
}
if (previousProximity != beacon.Proximity) {
Console.WriteLine (message);
}
previousProximity = beacon.Proximity;
}
};
locationManager.StartRangingBeacons (region);
var db = new SQLite.SQLiteConnection (_pathToDatabase);
var bridgeIp = db.Table<HueBridge> ().ToArray ();
client = new LocalHueClient (bridgeIp [0].HueBridgeIpAddress);
client.Initialize ("pooberry");
}
示例8: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
// request location access from user
CLLocationManager lm = new CLLocationManager();
lm.RequestWhenInUseAuthorization();
}
示例9: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// get access
locationManager = new CLLocationManager ();
locationManager.RequestWhenInUseAuthorization ();
// create the annotation
var sdAnnotation = new MKPointAnnotation {
Title = "SDWebImage Annotation",
};
// create the view
string pId = "sdwebimage";
mapView.GetViewForAnnotation = (mapView, annotation) => {
if (annotation is MKUserLocation)
return null;
// create annotation view
var pinView = mapView.DequeueReusableAnnotation (pId);
if (pinView == null) {
pinView = new MKAnnotationView (annotation, pId);
// get the image
pinView.SetImage (
new NSUrl ("http://radiotray.sourceforge.net/radio.png"),
UIImage.FromBundle ("placeholder.png"),
(image, error, cacheType, imageUrl) => {
if (error != null) {
Console.WriteLine ("Error: " + error);
} else {
Console.WriteLine ("Done: " + pinView.GetImageUrl ());
}
});
}
return pinView;
};
// add the annotation
mapView.AddAnnotation (sdAnnotation);
// move it
mapView.DidUpdateUserLocation += (sender, e) => {
var loc = e.UserLocation.Coordinate;
sdAnnotation.Coordinate = new CLLocationCoordinate2D (loc.Latitude, loc.Longitude);
mapView.SetCenterCoordinate (sdAnnotation.Coordinate, true);
};
// start tracking
mapView.ShowsUserLocation = true;
}
示例10: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
var locationManager = new CLLocationManager();
locationManager.RequestWhenInUseAuthorization();
var peripheralData = _beaconRegion.GetPeripheralData(null);
_peripheralManager.StartAdvertising(peripheralData);
}
示例11: ViewDidLoad
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
//set up sqlite db
var documents = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
_pathToDatabase = Path.Combine (documents, "db_sqlite-net.db");
TryToConnectToBridge ();
utilityManager = new UtilityManager ();
beaconManager = new BeaconManager ();
locationManager = new CLLocationManager ();
locationManager.RequestWhenInUseAuthorization ();
beaconManager.AuthorizationStatusChanged += (sender, e) => {
beaconManager.StartMonitoringForRegion (region);
};
beaconManager.ExitedRegion += (sender, e) => {
proximityValueLabel.Text = "You have EXITED the PooBerry region";
};
locationManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {
switch (e.State) {
case CLRegionState.Inside:
OnAdd ();
Console.WriteLine ("region state inside");
break;
case CLRegionState.Outside:
Console.WriteLine ("region state outside");
StartMonitoringBeacons ();
break;
case CLRegionState.Unknown:
default:
Console.WriteLine ("region state unknown");
StartMonitoringBeacons ();
break;
}
};
locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => {
Console.WriteLine ("beacon region entered");
};
#region Hue UI
connectBridge.TouchUpInside += ConnectBridgeClicked;
onButton.TouchUpInside += OnButton_TouchUpInside;
offButton.TouchUpInside += OffButton_TouchUpInside;
#endregion Hue UI
}
示例12: PlatformSpecificStart
protected override void PlatformSpecificStart(MvxLocationOptions options)
{
lock (this)
{
if (_locationManager != null)
throw new MvxException("You cannot start the MvxLocation service more than once");
_locationManager = new CLLocationManager();
_locationManager.Delegate = new LocationDelegate(this);
if (options.MovementThresholdInM > 0)
{
_locationManager.DistanceFilter = options.MovementThresholdInM;
}
else
{
_locationManager.DistanceFilter = CLLocationDistance.FilterNone;
}
_locationManager.DesiredAccuracy = options.Accuracy == MvxLocationAccuracy.Fine ? CLLocation.AccuracyBest : CLLocation.AccuracyKilometer;
if (options.TimeBetweenUpdates > TimeSpan.Zero)
{
Mvx.Warning("TimeBetweenUpdates specified for MvxLocationOptions - but this is not supported in iOS");
}
if (options.TrackingMode == MvxLocationTrackingMode.Background)
{
if (IsIOS8orHigher)
{
_locationManager.RequestAlwaysAuthorization ();
}
else
{
Mvx.Warning ("MvxLocationTrackingMode.Background is not supported for iOS before 8");
}
}
else
{
if (IsIOS8orHigher)
{
_locationManager.RequestWhenInUseAuthorization ();
}
}
if (CLLocationManager.HeadingAvailable)
_locationManager.StartUpdatingHeading();
_locationManager.StartUpdatingLocation();
}
}
示例13: ViewDidLoad
public override void ViewDidLoad()
{
base.ViewDidLoad();
map.SetRegion(
new MKCoordinateRegion(
centerPosition, // 初期位置
new MKCoordinateSpan(0.1d, 0.1d)),
true);
locMgr = new CLLocationManager();
locMgr.RequestWhenInUseAuthorization();
button.TouchUpInside += (s, _) =>
{
locMgr.DesiredAccuracy = 1000;
locMgr.LocationsUpdated += async (object sender, CLLocationsUpdatedEventArgs e) =>
{
var location = e.Locations[e.Locations.Length - 1];
LatitudeText.Text = "Lat: " + location.Coordinate.Latitude.ToString("N6");
LongitudeText.Text = "Lon: " + location.Coordinate.Longitude.ToString("N6");
// PCL で Google Maps API Web サービスに Lat, Lon を投げて住所を取得しています。
var addr = await getAddress.GetJsonAsync(location.Coordinate.Latitude, location.Coordinate.Longitude) ?? "取得できませんでした";
System.Diagnostics.Debug.WriteLine("AddressResult", addr);
AddrText.Text = "Address: " + addr;
// Map 移動
map.SetRegion(
new MKCoordinateRegion(
new CLLocationCoordinate2D(location.Coordinate.Latitude, location.Coordinate.Longitude),
new MKCoordinateSpan(0.1d, 0.1d)),
true);
// Pin 追加
map.AddAnnotations(new MKPointAnnotation()
{
Title = addr,
Coordinate = new CLLocationCoordinate2D(location.Coordinate.Latitude, location.Coordinate.Longitude)
});
locMgr.StopUpdatingLocation();
};
locMgr.StartUpdatingLocation(); // なぜ下に書くのかあめいさんに聞いてみよう。
};
}
示例14: InitializeMap
void InitializeMap ()
{
locationManager = new CLLocationManager ();
if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
locationManager.RequestWhenInUseAuthorization ();
}
map = new MKMapView (UIScreen.MainScreen.Bounds);
View.Add (map);
if (CLLocationManager.LocationServicesEnabled) {
map.ShowsUserLocation = true;
}
Helpers.CenterOnCheyenne (map);
}
示例15: StartLocationManager
public void StartLocationManager()
{
LocationManager = new CLLocationManager();
//if (LocationManager.RespondsToSelector(new MonoTouch.ObjCRuntime.Selector("requestWhenInUseAuthorization")))
LocationManager.RequestWhenInUseAuthorization();
LocationManager.DistanceFilter = CLLocationDistance.FilterNone;
LocationManager.DesiredAccuracy = CLLocation.AccuracyBest;
LocationManager.LocationsUpdated += LocationManager_LocationsUpdated;
LocationManager.StartUpdatingLocation();
_isTracking = true;
System.Diagnostics.Debug.WriteLine("Location manager started ");
}