locked
Xamarin.iOS 8.2 breaks Xamarin.Mobile geolocation alert RRS feed

  • Question

  • User38988 posted

    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

    Monday, October 6, 2014 2:41 PM

All replies

  • User39 posted

    Can you install Xamarin.iOS 8.0 (only) in order to narrow down what's causing the problem? You can download it from here: https://store.xamarin.com/account/my/subscription/downloads - and if that still works, try downgrading Xamarin Studio as well.

    Monday, October 6, 2014 3:28 PM
  • User38988 posted

    @RolfBjarneKvinge

    Thanks for the quick reply.

    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

    Monday, October 6, 2014 5:20 PM
  • User39 posted

    @joemath: thanks a lot for narrowing it down, could you please file a bug (http://bugzilla.xamarin.com) with your project so that we can have a look at it (file under the Xamarin.iOS component)?

    Tuesday, October 7, 2014 1:41 PM
  • User38988 posted

    @RolfBjarneKvinge?

    I added Bug 23669 and included a sample project.

    Thanks for your help!

    Tuesday, October 7, 2014 5:20 PM
  • User38988 posted

    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 in the class
    // Save a reference to the CLLocationManager so that it stays in scope
    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 info here about the "disappearing" alert: stackoverflow.com/a/25521430

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

    Saturday, October 11, 2014 7:52 PM
  • User69600 posted

    I posted my own thread with a similar question. When I go to the downloads section it only shows past versions for Xamarin Studio. How can I get an older version of Xamarin.iOS?

    Saturday, October 11, 2014 11:30 PM
  • User38988 posted

    @TaylorArtunian?

    1. Login to your account on the Xamarin website.
    2. On the left side, choose "Downloads".
    3. In the middle section, click the "View all versions" link. A matrix appears that allows you download back versions of Xamarin.iOS and other products.
    Sunday, October 12, 2014 10:25 PM
  • User65556 posted

    Check this out: http://matthewfecher.com/app-developement/getting-gps-location-using-core-location-in-ios-8-vs-ios-7/

    Friday, October 31, 2014 2:26 PM
  • User60408 posted

    I am writing native via Xcode but came across this same issue in iOS 8. Additional key definitions are required for the privacy prompts. I'll take a guess and say this is the issue here as well.

    Make sure that you specify the following key in your info.plist for the app: NSLocationWhenInUseUsageDescription.

    Search "NSLocationWhenInUseUsageDescription" here: (https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/)

    Wednesday, December 24, 2014 5:32 PM