Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS 17.4, Barometer.Default.Start hangs indefinately #20930

Open
sbloom82 opened this issue Feb 29, 2024 · 12 comments
Open

iOS 17.4, Barometer.Default.Start hangs indefinately #20930

sbloom82 opened this issue Feb 29, 2024 · 12 comments
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Milestone

Comments

@sbloom82
Copy link

Description

I have an app that uses the barometer and initializes it upon app startup. On iOS 17.4, calling Barometer.Start() results a hang. Using the debugger, we can see the exception thrown in the output window. The exception is not bubbled out to the caller, so it cannot be handled.

Steps to Reproduce

Using this code, running on iOS 17.4, the call to Start() hangs indefinitely

var _isBarometerEnabled = Barometer.Default.IsSupported;
if (_isBarometerEnabled)
{
Barometer.Default.ReadingChanged += Barometer_ReadingChanged;
Barometer.Default.Start(SensorSpeed.Default);
}

Link to public reproduction project repository

No response

Version with bug

8.0.6 SR1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

8.0.6 SR1

Affected platforms

iOS

Affected platform versions

iOS 17.4

Did you find any workaround?

No workaround, other than not using the Barometer

Relevant log output

*** Terminating app due to uncaught exception 'System.NullReferenceException', reason: 'Object reference not set to an instance of an object. (System.NullReferenceException)
   at Microsoft.Maui.Devices.Sensors.BarometerImplementation.<PlatformStart>g__LocationManagerUpdatedHeading|19_0(CMAltitudeData e, NSError error)
   at ObjCRuntime.Trampolines.SDActionArity2V67.Invoke(IntPtr block, NativeHandle arg1, NativeHandle arg2) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs:line 34164
   at CoreMotion.CMAltimeter.StartRelativeAltitudeUpdates(NSOperationQueue queue, Action`2 handler) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/CoreMotion/CMAltimeter.g.cs:line 117
   at Microsoft.Maui.Devices.Sensors.BarometerImplementation.PlatformStart(SensorSpeed sensorSpeed)
   at Microsoft.Maui.Devices.Sensors.BarometerImplementation.Start(SensorSpeed sensorSpeed)
'
*** First throw 
sers/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/ObjCRuntime/Trampolines.g.cs:line 34164
   at CoreMotion.CMAltimeter.StartRelativeAltitudeUpdates(NSOperationQueue queue, Action`2 handler) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/CoreMotion/CMAltimeter.g.cs:line 117
   at Microsoft.Maui.Devices.Sensors.BarometerImplementation.PlatformStart(SensorSpeed sensorSpeed)
   at Microsoft.Maui.Devices.Sensors.BarometerImplementation.Start(SensorSpeed sensorSpeed)
'
*** First throw call stack:
(0x1a04ceb28 0x19833ef78 0x100ea21e0 0x100ea1d00 0x100ea1cb0 0x1011bc130 0x1011baca8 0x1011e1abc 0x1011dfd80 0x1011dad34 0x1011d2854 0x100e71a18 0x100eb6044 0x1011e2264 0x1011e0bac 0x1011d55b8 0x1011d3184 0x1011a1e10 0x1011495dc 0x10115e8b4 0x1fc3cda90 0x1fc3ccfcc)
*** Terminating app due to uncaught exception 'System.NullReferenceException', reason: 'Object reference not set to an instance of an object. (System.NullReferenceException)
   at Microsoft.
vices.Sensors.BarometerImplementation.Start(SensorSpeed sensorSpeed)
@sbloom82 sbloom82 added the t/bug Something isn't working label Feb 29, 2024
@jsuarezruiz jsuarezruiz added platform/iOS 🍎 area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info labels Mar 1, 2024
@jfversluis
Copy link
Member

Are you testing this on an actual device or the Simulator? I can imagine this is one thing that is not implemented in the Simulator. Also you indicate that this has worked in previous .NET MAUI versions? Can you confirm that? Do you know which version exactly?

@jfversluis jfversluis added the s/needs-info Issue needs more info from the author label Mar 1, 2024
@ghost
Copy link

ghost commented Mar 1, 2024

Hi @sbloom82. We have added the "s/needs-info" label to this issue, which indicates that we have an open question for you before we can take further action. This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@samhouts samhouts added the potential-regression This issue described a possible regression on a currently supported version., verification pending label Mar 1, 2024
@jsuarezruiz jsuarezruiz added s/needs-repro Attach a solution or code which reproduces the issue and removed s/needs-info Issue needs more info from the author labels Mar 4, 2024
@ghost
Copy link

ghost commented Mar 4, 2024

Hi @sbloom82. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

@dzungpv
Copy link

dzungpv commented Mar 5, 2024

I have same problem but on native framework, it cause by the iOS so you must report to Apple.

@ghost ghost added s/needs-attention Issue has more information and needs another look and removed s/needs-repro Attach a solution or code which reproduces the issue labels Mar 5, 2024
@janusw
Copy link
Contributor

janusw commented Mar 6, 2024

Are you testing this on an actual device or the Simulator? I can imagine this is one thing that is not implemented in the Simulator.

No, this is not a simulator issue. I see the NullReferenceException on a real device after updating to iOS 17.4 ... (iPad Air 4th gen)

@janusw
Copy link
Contributor

janusw commented Mar 6, 2024

at CoreMotion.CMAltimeter.StartRelativeAltitudeUpdates(NSOperationQueue queue, Action`2 handler) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/CoreMotion/CMAltimeter.g.cs:line 117
at Microsoft.Maui.Devices.Sensors.BarometerImplementation.PlatformStart(SensorSpeed sensorSpeed)
at Microsoft.Maui.Devices.Sensors.BarometerImplementation.Start(SensorSpeed sensorSpeed)

Seems like the interface of CMAltitudeHandler changed, which is a parameter of CMAltimeter.StartRelativeAltitudeUpdates:

https://developer.apple.com/documentation/coremotion/cmaltitudehandler?changes=latest_minor

@sbloom82
Copy link
Author

sbloom82 commented Mar 6, 2024

Are you testing this on an actual device or the Simulator? I can imagine this is one thing that is not implemented in the Simulator. Also you indicate that this has worked in previous .NET MAUI versions? Can you confirm that? Do you know which version exactly?

We encountered this issue in our production app on real devices for users who updated to iOS 17.4 beta. Our app initializes the barometer on startup, so this caused the app to hang on startup and never fully load.

This has worked since we implemented it in our maui 8 app. Users who are not on iOS 17.4 have an app that is working as expected. We had to issue an update to skip barometer initialization for 17.4 ios devices.

@jfversluis
Copy link
Member

Seems like this might have to do with #21057 then maybe?

@jfversluis jfversluis removed the s/needs-attention Issue has more information and needs another look label Mar 6, 2024
@jfversluis jfversluis added this to the Backlog milestone Mar 6, 2024
@janusw
Copy link
Contributor

janusw commented Mar 6, 2024

Our app initializes the barometer on startup, so this caused the app to hang on startup and never fully load.

Hm, why does it hang? I see a hard crash, unfortunately :/

In my case, Barometer.Start is actually inside a try-catch block, but still the NullReferenceException is not caught. So, yes, the only way around this is not to use the barometer.

@janusw
Copy link
Contributor

janusw commented Mar 6, 2024

Seems like this might have to do with #21057 then maybe?

Yes, it's certainly related to API changes in XCode 15.3 / iOS 17.4.

@janusw
Copy link
Contributor

janusw commented Mar 6, 2024

Also you indicate that this has worked in previous .NET MAUI versions? Can you confirm that? Do you know which version exactly?

I'm not aware of any previous MAUI version that works, but it seems that the Barometer class from Xamarin.Essentials does not crash in the same way. In that sense it's a regression wrt Xamarin.

Certainly the Xamarin code suffers from the API change as well. I assume the difference is that the exception is catchable there. I don't understand why it is not in MAUI, but for me this is actually the biggest issue (if the exception was catchble, the API change would be half as bad).

@sbloom82
Copy link
Author

sbloom82 commented May 17, 2024

Now that apple has released ios 17.5 (and the 17.4 minor versions), when "Motion & Fitness" permission is not granted, the app will crash after starting the barometer.

Here's all of my work arounds

        private async Task InitBarometer()
        {
            try
            {
#if IOS
                var version = DeviceInfo.Current.Version;
                if (version.Major == 17 && version.Minor == 4)
                {
                    _barometerDisabledReason = "Barometer is disabled for iOS 17.4. Update to iOS 17.5 to enable.";
                    throw new Exception(_barometerDisabledReason);
                }
                var status = await Permissions.CheckStatusAsync<Permissions.Sensors>();
                if (status != PermissionStatus.Granted)
                {
                    _barometerDisabledReason = "Barometer is disabled. Please grant permission to 'Motion & Fitness' to enable.";
                    throw new Exception(_barometerDisabledReason);
                }
#endif

                _isBarometerEnabled = Barometer.Default.IsSupported;
                if (_isBarometerEnabled)
                {
                    Barometer.Default.ReadingChanged += Barometer_ReadingChanged;
                    Barometer.Default.Start(SensorSpeed.Default);
                }
            }
            catch
            {                
                _isBarometerEnabled = false;
            }
            await Task.CompletedTask;
        }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-essentials Essentials: Device, Display, Connectivity, Secure Storage, Sensors, App Info platform/iOS 🍎 potential-regression This issue described a possible regression on a currently supported version., verification pending t/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants