Bug 1998 - CLLocationManager.Failed() not called when Location Services are turned off for device
Summary: CLLocationManager.Failed() not called when Location Services are turned off f...
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2011-11-10 14:48 UTC by Andrew Young
Modified: 2011-11-10 17:15 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

sample app (8.90 KB, application/zip)
2011-11-10 14:48 UTC, Andrew Young

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Andrew Young 2011-11-10 14:48:13 UTC
Created attachment 867 [details]
sample app

Steps to reproduce.

1. on iPhone, go to Settings > General > Reset > Reset Location Warnings
2. on iPhone go to Settings > Location Services > Turn it off completely for
the phone just to be sure
3. build and deploy app
4. when prompted to turn on location services hit "Cancel"
5. verify that nothing gets printed to console
Comment 1 Sebastien Pouliot 2011-11-10 15:32:06 UTC
I can reproduce. I will check how an objectiveC application behave in such condition.
Comment 2 Andrew Young 2011-11-10 15:35:15 UTC
Even stranger is that after you hit cancel, minimize the app, bring the app back to foreground. Sometimes the message pops up again. Do that one or two more times and the app stops responding.
Comment 3 Sebastien Pouliot 2011-11-10 15:55:57 UTC
I used Apple's Locations sample [1] and got the same result, i.e. "locationManager:didFailWithError:" (Failed in MonoTouch) is _not_ called if the location service is turned off. Documentation [2] is not very clear but it does not cover this case (service off) only the case where the user denies the application.

However you can workaround this by doing this:

		public override void ViewDidAppear (bool animated)
			base.ViewDidAppear (animated);
			if (!CLLocationManager.LocationServicesEnabled)
				Failed (this, new NSErrorEventArgs (new NSError ()));
			_manager.StartUpdatingLocation ();

which directly called Failed (to share logic) and also disable/remove the iOS alert that ask you if you wish to start the location service (if its something you're looking for).

[1] http://developer.apple.com/library/IOS/#samplecode/Locations/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008406

[2] http://developer.apple.com/library/IOS/#documentation/CoreLocation/Reference/CLLocationManagerDelegate_Protocol/CLLocationManagerDelegate/CLLocationManagerDelegate.html#//apple_ref/occ/intfm/CLLocationManagerDelegate/locationManager:didFailWithError:
Comment 4 Sebastien Pouliot 2011-11-10 16:01:06 UTC
> Sometimes the message pops up again.

I suspect that's because the application sometimes resume (not showing the alert) and other times it is restarted (showing the alert again).
Comment 5 Andrew Young 2011-11-10 17:15:26 UTC
Thanks for looking into it. Yes, the documentation could be a little more explicit.