Bug 23669 - Xamarin.iOS 8.2 breaks Xamarin.Mobile geolocation alert
Summary: Xamarin.iOS 8.2 breaks Xamarin.Mobile geolocation alert
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: XI 8.2.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-10-07 13:17 UTC by jmather
Modified: 2014-10-13 06:30 UTC (History)
3 users (show)

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


Attachments
GeolocationAlert Sample Project (911.48 KB, application/zip)
2014-10-07 13:17 UTC, jmather
Details


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:
Status:
RESOLVED FIXED

Description jmather 2014-10-07 13:17:34 UTC
Created attachment 8341 [details]
GeolocationAlert Sample Project

LINK TO ORIGINAL PROBLEM DESCRIPTION IN XAMARIN FORUMS:

  http://forums.xamarin.com/discussion/25476/xamarin-ios-8-2-breaks-xamarin-mobile-geolocation-alert


ATTACHED IS A SAMPLE PROJECT THAT DEMONSTRATES THE PROBLEM:

  * With Xamarin.iOS 8.0, the geolocation permission popup appears when the app first launches
  * With Xamarin.iOS 8.2, the geolocation permission popup DO NOT appear when the app first launches


FULL PROBLEM DESCRIPTION:

My iOS app uses the Xamarin.Mobile component (V0.7.3) for geolocation. Until today, the app worked great on my iPhone and iPad (both iOS 8.0.2).

This morning I installed the Xamarin update from the Stable channel that includes Xamarin Studio 5.5 and Xamarin.iOS 8.2. Now geolocation has stopped working and it appears to be a permission problem.

Specifically, the location permission alert (“Allow ‘app’ to access your location while you use the app?”) no longer appears when my app launches. The GPS never turns on, and my app never gets a fix.

On the device, if I go into Settings -> Privacy -> Location Services, my app is in the list but the setting is blank. It should be “While Using”. If I manually change it to “While Using”, then geolocation starts working again in my app.

Something in the Xamarin update broke the permission alert. The alert needs to appear automatically so that users don’t have to go digging through Settings to enable geolocation.

My app targets iOS 8. My Info.plist contains “NSLocationWhenInUseUsageDescription”. I have this code in my startup processing:

    // Request geoloation authorization
    var locationManager = new MonoTouch.CoreLocation.CLLocationManager();
    if (locationManager.RespondsToSelector (new MonoTouch.ObjCRuntime.Selector ("requestWhenInUseAuthorization")))
    {
        locationManager.RequestWhenInUseAuthorization ();
    } 

Again, everything worked great on the device until I updated the Xamarin tools this morning.

I tried upgrading to Xamarin.Mobile V0.7.4, but it didn’t fix the problem. The permission alert still does not appear.

I’m developing in a virtual machine and I can swap between the working (original) and broken (new) configurations. My project files are identical. With the original tools, the alert appears. With the new tools installed this morning, no alert appears.

Anyone else running into this problem? I’m reverting to the original tools until this issue is resolved.

Configuration details...

Working (Original) Tools:
* Xamarin Mobile 0.7.3
* Xamarin Studio Version 5.4 (build 240)
* Xamarin.Android Version: 4.16.0 (Indie Edition)
* Xamarin.iOS Version: 8.0.0.63 (Indie Edition)
* Xcode 6.0.1 (6528)
* Mac OS X 10.9.5

Broken (New) Tools Installed Today:
* Xamarin Mobile 0.7.3 or 0.7.4
* Xamarin Studio Version 5.5 (build 227)
* Xamarin.Android Version: 4.18.0 (Indie Edition)
* Xamarin.iOS Version: 8.2.0.193 (Indie Edition)
* Xcode 6.0.1 (6528)
* Mac OS X 10.9.5


=================================================

FOLLOW-UP TESTING REQUESTED BY @RolfBjarneKvinge:

I tested three configurations:
1. Original setup.
2. Original setup with Xamarin.iOS upgraded to 8.2.
3. Original setup with Xamarin Studio upgraded to 5.5.

Full results below. Bottom line is that the problem is in Xamarin.iOS 8.2. Xamarin Studio 5.5 worked fine.


CONFIGURATION #1: Original Setup
* Xamarin Studio Version 5.4 (build 240)
* Xamarin.iOS Version 8.0.0.63 (Indie Edition)

TEST 1a. Debug build on iPhone. NO ALERT.
TEST 1b. Release build on iPhone. ALERT.
TEST 1c. AdHoc build on iPhone. ALERT.
PASS


CONFIGURATION #2: Original (#1) upgraded to Xamarin.iOS 8.2
* Xamarin Studio Version 5.4 (build 240)
* Xamarin.iOS Version 8.2.0.193 (Indie Edition)

TEST 2a. Debug build on iPhone. NO ALERT.
TEST 2b. Release build on iPhone. NO ALERT.
TEST 2c. AdHoc build on iPhone. NO ALERT.
FAIL


CONFIGURATION #3: Original (#1) upgraded to Xamarin Studio 5.5
* Xamarin Studio Version 5.5 (build 227)
* Xamarin.iOS Version 8.0.0.63 (Indie Edition)

TEST 3a. Debug build on iPhone. NO ALERT.
TEST 3b. Release build on iPhone. ALERT.
TEST 3c. AdHoc build on iPhone. ALERT.
PASS


All configurations had these in common:
* iPhone 5s, iOS V8.0.2
* Xamarin Mobile 0.7.3
* Xamarin.Android Version: 4.16.0 (Indie Edition)
* Xcode 6.0.1 (6528)
* Mac OS X 10.9.5
Comment 1 Rajneesh Kumar 2014-10-09 04:23:33 UTC
I have checked this issue and unable to reproduce this. To reproduce this issue I have followed the sample application and instruction provided in bug description.

Steps I have followed:

1. Open attached sample application in XS
2. Build and deploy the application on device
3. Observe that an pop up will appear when application first launches:
     ' "GeolocationAlert.iOS" Would you Like to Use Your Current Location ' 
With two Button "Don't Allow" and "OK"

Additional Information: I observed that the pop up appear when the application first launch. I also observed that the pop up appear in the both environment info provided in bug description. I if I manually turn "OFF" the location services I get the different pop up, provided in screenshot.

Could you please provide steps to reproduce or please let me know that what steps I am missing to reproduce this issue.

Pop up Screenshot:
When Location Services "OFF" : http://www.screencast.com/t/U29fYic14
When Location Services "ON" :  http://www.screencast.com/t/EXHylC0YX

Screencast: http://www.screencast.com/t/jx9rB8vss

Environment Info:

=== Xamarin Studio ===

Version 5.5 (build 227)
Installation UUID: 45555ffd-f3f0-4f29-9543-e369d711ab7d
Runtime:
	Mono 3.10.0 ((detached/47db868)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000019

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.Mac ===

Version: 1.10.0.13 (Enterprise Edition)

=== Xamarin.iOS ===

Version: 8.2.0.193 (Enterprise Edition)
Hash: 959c1e4
Branch: 
Build date: 2014-10-03 00:25:37-0400

=== Xamarin.Android ===

Version: 4.18.0 (Enterprise Edition)
Android SDK: /Users/xamarin77/Desktop/android-sdk-macosx
	Supported Android versions:
		2.1    (API level 7)
		2.2    (API level 8)
		2.3    (API level 10)
		3.1    (API level 12)
		3.2    (API level 13)
		4.0    (API level 14)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		4.5    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Build Information ===

Release ID: 505000227
Git revision: 7b721eeec7a2fa4c4f4de0ecd2aed4dc25edac95
Build date: 2014-10-02 15:53:38-04
Xamarin addins: 99ed56b428b31eba1efaace4d82188d6f334e6ca

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin77s-Mac-mini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 2 jmather 2014-10-11 00:03:31 UTC
I did a full uninstall then reinstall of Xamarin Studio, and the issue still occurs.

I did notice something different, though, after the reinstall.  The first time I deployed and ran the Ad Hoc build, the permission alert appeared for a fraction of a second (about 1/4 second).  Then the alert disappeared.  It wasn't on the screen long enough to read or tap.  But I did see it flicker on for a split second before it disappeared.  After that, every time I uninstall, reinstall, and run the app there is no permission alert.  Not even for a split second like I saw with the first install.

Differences between your tests and my tests:
* You tested with Xamarin Enterprise.  I'm using Xamarin Indie.
* In the screencast, it seems you used an iPhone 5.  I'm using an iPhone 5s with iOS 8.0.2.
* At the very end of the screencast, it looked like you were going to try one Ad Hoc build.  I'm repeatedly testing with Ad Hoc builds (i.e. build, deploy, run, repeat).

Is there something I should try on my side to help isolate the issue?


Environment Info:

=== Xamarin Studio ===

Version 5.5 (build 227)
Installation UUID: 0cbb5348-f40b-468e-a5b6-6570fe5bb9b0
Runtime:
	Mono 3.10.0 ((detached/47db868)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 310000019

=== Xamarin.Android ===

Version: 4.18.0 (Indie Edition)
Android SDK: /Users/jmather/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		2.1   (API level 7)
		2.2   (API level 8)
		2.3   (API level 10)
		3.1   (API level 12)
		4.0.3 (API level 15)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.Mac ===

Version:

=== Xamarin.iOS ===

Version: 8.2.0.193 (Indie Edition)
Hash: 959c1e4
Branch: 
Build date: 2014-10-03 00:25:37-0400

=== Build Information ===

Release ID: 505000227
Git revision: 7b721eeec7a2fa4c4f4de0ecd2aed4dc25edac95
Build date: 2014-10-02 15:53:38-04
Xamarin addins: 99ed56b428b31eba1efaace4d82188d6f334e6ca

=== Operating System ===

Mac OS X 10.9.5
Darwin joes-mac-2.attlocal.net 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 3 jmather 2014-10-11 15:42:59 UTC
I figured out the problem.

The permission alert goes away (or doesn't show at all) if the CLLocationManager goes out of scope.  The solution is to maintain a reference to the CLLocationManager throughout location processing.

Here's the original code.  It fails with no alert or a very brief alert:

    // Request geoloation authorization
    var locationManager = new MonoTouch.CoreLocation.CLLocationManager();
    if (locationManager.RespondsToSelector (new MonoTouch.ObjCRuntime.Selector("requestWhenInUseAuthorization")))
    {
        locationManager.RequestWhenInUseAuthorization ();
    } 

Here's the new code.  It succeeds with the alert staying on screen:

    // Member variable of the class
    protected MonoTouch.CoreLocation.CLLocationManager locationManager = null; 

    ...

    // Some method in the class
    // Request geoloation authorization
    locationManager = new MonoTouch.CoreLocation.CLLocationManager();
    if (locationManager.RespondsToSelector (new MonoTouch.ObjCRuntime.Selector("requestWhenInUseAuthorization")))
    {
        locationManager.RequestWhenInUseAuthorization ();
    } 

Additional reference here:

   http://stackoverflow.com/a/25521430

Something changed between Xamarin.iOS 8.0 and 8.2 that caused this issue to bubble to the surface.

You can close this bug.

Thank you.
Comment 4 Rolf Bjarne Kvinge [MSFT] 2014-10-13 06:30:44 UTC
Thanks for reporting back to us; it now makes sense (I've tried a few times to reproduce, but was unable to). What likely happened is that the GC kicks in at a different time in 8.2 than 8.0 (this could be such a simple thing as a different memory usage pattern on our side).