"would like to use your current location" - message dissapers before user can click on it.

ColinEberhardtColinEberhardt GBMember, Insider
edited October 2012 in Xamarin.iOS

Hi All,

I have been integrating location into an application and have stumbled on a problem. The pop-up message where the user indicates that they are happy to share their location is disappearing before the user has a chance to select "OK" or "Don't Allow". I have created a single-view app, with just the following lines of code within ViewDidLoad:

var locationManager = new CLLocationManager();
locationManager.LocationsUpdated += (s,e) =>
{
  Debug.WriteLine("Woo Hoo!");
}
locationManager.StartUpdatingLocations();

The pop up appears for about 1/2 a second then vanishes again. Has anyone else observed this? or better still have a fix for this!

Colin E.

Best Answer

  • andywhittandywhitt GB
    edited October 2012 Accepted Answer

    Hi Colin, you need to make locationManager a class level variable.

    LLocationManager _locationManager;
    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        _locationManager = new CLLocationManager();
        _locationManager.LocationsUpdated += (s,e) =>
        {
            Debug.WriteLine("Woo Hoo!");
        };
        _locationManager.StartUpdatingLocation();
    }
    

Answers

  • andywhittandywhitt GBMember
    edited October 2012 Accepted Answer

    Hi Colin, you need to make locationManager a class level variable.

    LLocationManager _locationManager;
    public override void ViewDidLoad ()
    {
        base.ViewDidLoad ();
        _locationManager = new CLLocationManager();
        _locationManager.LocationsUpdated += (s,e) =>
        {
            Debug.WriteLine("Woo Hoo!");
        };
        _locationManager.StartUpdatingLocation();
    }
    
  • ColinEberhardtColinEberhardt GBMember, Insider

    Thanks - that was a nice simple fix :-)

Sign In or Register to comment.