Essentials: [Bug] iOS Crash in Permissions.LocationWhenInUse on WiFi iPad Air

Created on 23 Apr 2020  路  16Comments  路  Source: xamarin/Essentials

Description

Since Xamarin.Essentials v1.5 I've been unable to pass App Store review for my iOS release because it's consistently crashed on launch for the iPad Air 3rd Gen (Wi-Fi Only). Unfortunately, I don't have this device, and so I've been unable to reproduce the bug myself.

Steps to Reproduce

  1. Submit app that uses Geolocation to Apple App Store for review.
  2. Wait a couple of days.
  3. They send you back crash logs (with no symbols), which only happen on iPad11,3.

Expected Behavior

My app was passing review prior to upgrading to Xamarin.Essentials v1.5, and the other changes made between releases were minor and unrelated to geolocation or permissions.

Actual Behavior

While the crash logs Apple provided were pretty useless, I was eventually able to collect a crash report from App Center:

Xamarin Exception Stack:
System.NullReferenceException: Object reference not set to an instance of an object
  at Xamarin.Essentials.Permissions+LocationWhenInUse+<>c__DisplayClass6_0.<RequestLocationAsync>g__LocationAuthCallback|0 (System.Object sender, CoreLocation.CLAuthorizationChangedEventArgs e) <0x105d1e7bc + 0x00164> in <68271ee3b0404411a54069b48d3f21d4#9ef9d2b073382932d73031f45271bd71>:0
  at CoreLocation.CLLocationManager+_CLLocationManagerDelegate.AuthorizationChanged (CoreLocation.CLLocationManager manager, CoreLocation.CLAuthorizationStatus status) <0x105b0dd94 + 0x0005f> in <698888335fd24bdca1317448cda6f409#9ef9d2b073382932d73031f45271bd71>:0
  at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
  at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) <0x105b19a50 + 0x0003f> in <698888335fd24bdca1317448cda6f409#9ef9d2b073382932d73031f45271bd71>:0
  at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) <0x105b199a8 + 0x00053> in <698888335fd24bdca1317448cda6f409#9ef9d2b073382932d73031f45271bd71>:0
  at TRC.iOS.Application.Main (System.String[] args) <0x104bb5d3c + 0x00033> in <eceeb997d168486eb5a288f271d7a734#9ef9d2b073382932d73031f45271bd71>:0

Basic Information

  • Version with issue: v1.5 and later
  • Last known good version: v1.4.x
  • IDE: VS 2019 16.5.4
  • Platform Target Frameworks:

    • Xamarin: 16.5.000.533

    • iOS: 13.16.0.13

  • Nuget Packages: Xamarin.Essentials v1.5.3, Xamarin.Forms v4.5.0.617
  • Affected Devices :iPad Air 3rd Gen (Wi-Fi Only) on iOS 13.4.1

Crash Logs

report-2518147145490009999-59d0254a-be58-4d50-97c1-35771fa503f6.txt
attachment-943117418417485701crashlog-F3EBBC9A-135D-4DFB-84E0-FD3C5A4F0631.txt
attachment-11792801170805798081crashlog-D9E94BF0-0F48-4B5C-ABD9-9249611043C5.txt
attachment-16624304168505407458crashlog-EC6EA85F-9E6A-49E3-A457-AFC7E9E6F070.txt
attachment-16894243783913967682crashlog-5E5364A0-DD92-4C8D-8A1E-E988085C20DD.txt
attachment-1694792491770359668crashlog-F5D1F2F4-C3A9-4E4A-A9FE-5E032CE741A5.txt
attachment-2126118544994147300crashlog-EB24FB64-D855-40C3-9328-2F27E91EB193.txt
attachment-4415367737349367811crashlog-36DEDAEA-A1DD-40EB-BBFC-02772A57C6F6.txt
attachment-7081511181916664364crashlog-E0AD848F-AF9A-4B94-B171-8B1B26957A45.txt
attachment-7887135452841600072crashlog-7D6005FC-3FC4-470D-B25E-0AA382EBF174.txt

bug in-progress

Most helpful comment

Hi, I'm, using Xamarin.Essentials of version 1.5.3.2 but still have the same issue sometimes.

System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Essentials.Permissions+LocationWhenInUse+<>c__DisplayClass6_0.<RequestLocationAsync>g__LocationAuthCallback|0 (System.Object sender, CoreLocation.CLAuthorizationChangedEventArgs e) [0x0004d] in d:\a\1\s\Xamarin.Essentials\Permissions\Permissions.ios.tvos.watchos.cs:185 at Xamarin.Essentials.Permissions+LocationWhenInUse.RequestAsync () [0x0005f] in d:\a\1\s\Xamarin.Essentials\Permissions\Permissions.ios.tvos.watchos.cs:109

I got this error on IPhone 7(iOS 13.5.1). I guess it happens when the "Never" access is selected for location in the settings.
Maybe it happens because of this line?
locationManager.AuthorizationChanged -= LocationAuthCallback;

All 16 comments

Can you list out what plugins you are using and also what APIs in Essentials you are using?

The only packages I'm using are:

  • Xamarin.Forms
  • Xamarin.Forms.Maps
  • Xamarin.Essentials
  • Newtonsoft.Json
  • Microsoft .AppCenter (including Analytics & Crashes)

In Essentials, I'm using:

  • Connectivity
  • Browser
  • PhoneDialer
  • Email
  • Accelerometer
  • Geolocation

Gotcha, so it seems like this may be happening when you are doing a geolocation API ... interesting.

I looked around the code and didn't see a lot of areas in which anything could be null... but put some checks in.

Did they give you reproduction steps? Like did they do one time, allow, or don't allow?

Would be helpful if you can try/catch your geolocation request and then track those exceptions in App Center. May have more useful data.

I assume you are just calling GetLocationAsync?

Well, I'm actually calling GetLastKnownLocationAsync() and then GetLocationAsync() if it returns null. It's already in a try/catch, so I don't believe the exception is occurring during that call.

Geolocator.zip

As for the repro steps, I can't say for sure because I don't have the hardware myself. I assume Apple is just running some automated testing which logs into my app using the test account that I give them. That should generate a permissions and geolocation request.

hmmmm, I did find a nasty regression that maybe is the cause if they press denied.

Can you try out: https://dev.azure.com/xamarin/public/_build/results?buildId=17497&view=artifacts&type=publishedArtifacts

I am pretty sure this will fix your issues.

Thanks, @JamesMontemagno! I've submitted the updated build for review on App Store Connect and will let you know as soon as I hear from Apple.

Unfortunately, that didn't fix the problem. We're still seeing the same crash, this time with a 6th gen, Wi-Fi iPad (iPad7,5). I think we can generalize the problem to iOS devices with no GPS module running iOS 13.4...but unfortunately the only WiFi iPad I have for testing can't run anything later than iOS 9.3.5 (which works fine). Here's the new App.Center crash report:

report-2518144378570009999-49083081-8165-4b03-b8a9-682bc419fe4e.txt

Note that the crash occurred 7h 19m 48s into their automated testing.

hmmm that is odd..... In all my years I have never seen anything like this and also we have had a lot of people submit apps with this and also my old plugin and they do very similar stuff.

I have one more thing I want to try..... Give this NuGet a try as I do a lot of stuff to detect if things are disabled and also lots of try/catching :)

https://dev.azure.com/xamarin/public/_build/results?buildId=17572&view=artifacts&type=publishedArtifacts

Success! That one passed the full App Store review test suite. Thanks for giving it another try, @jamesmontemagno!

I had the same issue on a iPhone 8, the NuGet preview seems to fix the issue.

Hi @jamesmontemagno

I am also getting this issue on iOS version 13.3 and using the latest version of Xamarin.Essential 1.5.3.1. Below are the crash report received on appcenter.

Permissions+LocationWhenInUse+<>c__DisplayClass6_0.g__LocationAuthCallback|0 (System.Object sender, CoreLocation.CLAuthorizationChangedEventArgs e)

路 CLLocationManager+_CLLocationManagerDelegate.AuthorizationChanged (CoreLocation.CLLocationManager manager, CoreLocation.CLAuthorizationStatus status)

路 (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)

路 UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate)

路 UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName)

路 Application.Main (System.String[] args)

Can you please help me on this.

Thank you.

1.5.3.2 has been published :)

Thanks a lot :)

Hi, I'm, using Xamarin.Essentials of version 1.5.3.2 but still have the same issue sometimes.

System.NullReferenceException: Object reference not set to an instance of an object at Xamarin.Essentials.Permissions+LocationWhenInUse+<>c__DisplayClass6_0.<RequestLocationAsync>g__LocationAuthCallback|0 (System.Object sender, CoreLocation.CLAuthorizationChangedEventArgs e) [0x0004d] in d:\a\1\s\Xamarin.Essentials\Permissions\Permissions.ios.tvos.watchos.cs:185 at Xamarin.Essentials.Permissions+LocationWhenInUse.RequestAsync () [0x0005f] in d:\a\1\s\Xamarin.Essentials\Permissions\Permissions.ios.tvos.watchos.cs:109

I got this error on IPhone 7(iOS 13.5.1). I guess it happens when the "Never" access is selected for location in the settings.
Maybe it happens because of this line?
locationManager.AuthorizationChanged -= LocationAuthCallback;

I have exactly the same problem as @artem-metliakov ... also on Xamarin.Essentials 1.5.3.2 and get the same crash & stack trace.

I have taken the liberty of creating a new issue since I noticed this one has already been closed:
https://github.com/xamarin/Essentials/issues/1325

Was this page helpful?
0 / 5 - 0 ratings