Reputation: 153
What we do
We are developing a mobile app in .NET MAUI that uses the Shiny NuGet packages to detect Bluetooth Beacons. I have a check in place (see code below) that is executed before the user opens a module in our app which uses Bluetooth Beacon detection to ensure that all necessary hardware is enabled.
The problem
This code works for any Android version from 8.1 to 14 that we tested and it works well on new iPhones, but it crashes for iOS 13.5 when calling RequestAccess
and I fail to understand why.
The source code
public async Task<string?> CheckAccess()
{
var beaconRangingManager = _serviceProvider.GetService<IBeaconRangingManager>();
var translationService = _serviceProvider.GetService<ITranslationService>();
if (beaconRangingManager != null && translationService != null)
{
var accessState = await beaconRangingManager.RequestAccess();
if (accessState != AccessState.Available)
{
return translationService.GetText("global_syn_permission_bluetooth");
}
}
return null;
}
The crash log
This is from the Visual Studio output when opening a module that uses Bluetooth Beacon detection and calls the code above. This happens every time on an iOS 13.5 device, but is fine for new iOS and any Android.
[0:] An error occurred: 'Objective-C exception thrown. Name: NSInvalidArgumentException Reason: -[CLLocationManager authorizationStatus]: unrecognized selector sent to instance 0x2918e2ed0
Native stack trace:
0 CoreFoundation 0x000000019a8a8314 AF42303F-57B6-3C11-8F18-8E80ABF7D886 + 1254164
1 libobjc.A.dylib 0x000000019a5bcc1c objc_exception_throw + 60
2 CoreFoundation 0x000000019a7a6a90 AF42303F-57B6-3C11-8F18-8E80ABF7D886 + 199312
3 CoreFoundation 0x000000019a8aca60 AF42303F-57B6-3C11-8F18-8E80ABF7D886 + 1272416
4 CoreFoundation 0x000000019a8aed60 _CF_forwarding_prep_0 + 96
5 Xamarin.PreBuilt.iOS 0x0000000100cffcbc xamarin_get_original_working_directory_path + 8596
6 Xamarin.PreBuilt.iOS 0x0000000100cbd95c Xamarin.PreBuilt.iOS + 12573020
7 Xamarin.PreBuilt.iOS 0x000000010102b434 AppleCryptoNative_X509ImportCollection + 2882424
8 Xamarin.PreBuilt.iOS 0x000000010101fb90 AppleCryptoNative_X509ImportCollection + 2835156
9 Xamarin.PreBuilt.iOS 0x000000010101d650 AppleCryptoNative_X509ImportCollection + 2825620
10 Xamarin.PreBuilt.iOS 0x0000000100fec228 AppleCryptoNative_X509ImportCollection + 2623852
11 Xamarin.PreBuilt.iOS 0x0000000100f938ec AppleCryptoNative_X509ImportCollection + 2261040
12 Xamarin.PreBuilt.iOS 0x0000000100f97670 AppleCryptoNative_X509ImportCollection + 2276788
13 Xamarin.PreBuilt.iOS 0x0000000100cf844c xamarin_get_runtime_arch + 35572
14 Xamarin.PreBuilt.iOS 0x0000000100cfedac xamarin_get_original_working_directory_path + 4740
15 Xamarin.PreBuilt.iOS 0x0000000100cffb90 xamarin_get_original_working_directory_path + 8296
16 UIKitCore 0x000000019e5ad90c 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 6469900
17 UIKitCore 0x000000019e5b6f10 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 6508304
18 UIKitCore 0x000000019e5b3908 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 6494472
19 UIKitCore 0x000000019e5b2e50 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 6491728
20 UIKitCore 0x000000019e5a67f0 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 6440944
21 UIKitCore 0x000000019e5a5f84 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 6438788
22 UIKitCore 0x000000019e5a5d40 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 6438208
23 UIKitCore 0x000000019ea2f2d4 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 11195092
24 UIKitCore 0x000000019ea0a45c 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 11043932
25 UIKitCore 0x000000019ea8da54 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 11582036
26 UIKitCore 0x000000019ea90648 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 11593288
27 UIKitCore 0x000000019ea88578 32D99ABD-E47B-38D8-BBD1-68AEA293A9A6 + 11560312
28 CoreFoundation 0x000000019a823af4 AF42303F-57B6-3C11-8F18-8E80ABF7D886 + 711412
29 CoreFoundation 0x000000019a823a48 AF42303F-57B6-3C11-8F18-8E80ABF7D886 + 711240
30 CoreFoundation 0x000000019a823198 AF42303F-57B6-3C11-8F18-8E80ABF7D886 + 709016
31 CoreFoundation 0x000000019a81df38 AF42303F-57B6-3C11-8F18-8E80ABF7D886 + 687928
32 CoreFoundation 0x000000019a81d8f4 CFRunLoopRunSpecific + 480
33 GraphicsServices 0x00000001a4c34604 GSEventRunModal + 164
34 UIKitCore 0x000000019e9f1358 UIApplicationMain + 1944
35 Xamarin.PreBuilt.iOS 0x0000000100cd45f4 xamarin_UIApplicationMain + 60
36 Xamarin.PreBuilt.iOS 0x000000010102c7a8 AppleCryptoNative_X509ImportCollection + 2887404
37 Xamarin.PreBuilt.iOS 0x000000010102b0a8 AppleCryptoNative_X509ImportCollection + 2881516
38 Xamarin.PreBuilt.iOS 0x000000010101fab8 AppleCryptoNative_X509ImportCollection + 2834940
39 Xamarin.PreBuilt.iOS 0x000000010101d650 AppleCryptoNative_X509ImportCollection + 2825620
40 Xamarin.PreBuilt.iOS 0x0000000100fec228 AppleCryptoNative_X509ImportCollection + 2623852
41 Xamarin.PreBuilt.iOS 0x0000000100f938ec AppleCryptoNative_X509ImportCollection + 2261040
42 Xamarin.PreBuilt.iOS 0x0000000100f9b370 AppleCryptoNative_X509ImportCollection + 2292404
43 Xamarin.PreBuilt.iOS 0x0000000100f57e90 AppleCryptoNative_X509ImportCollection + 2016724
44 Xamarin.PreBuilt.iOS 0x0000000100f6252c AppleCryptoNative_X509ImportCollection + 2059376
45 Xamarin.PreBuilt.iOS 0x000000010102c774 AppleCryptoNative_X509ImportCollection + 2887352
46 Xamarin.PreBuilt.iOS 0x000000010102b0e0 AppleCryptoNative_X509ImportCollection + 2881572
47 Xamarin.PreBuilt.iOS 0x000000010101fab8 AppleCryptoNative_X509ImportCollection + 2834940
48 Xamarin.PreBuilt.iOS 0x000000010101d650 AppleCryptoNative_X509ImportCollection + 2825620
49 Xamarin.PreBuilt.iOS 0x0000000100fec228 AppleCryptoNative_X509ImportCollection + 2623852
50 Xamarin.PreBuilt.iOS 0x0000000100f938ec AppleCryptoNative_X509ImportCollection + 2261040
51 Xamarin.PreBuilt.iOS 0x0000000100f99be8 AppleCryptoNative_X509ImportCollection + 2286380
52 Xamarin.PreBuilt.iOS 0x0000000100ff1844 AppleCryptoNative_X509ImportCollection + 2645896
53 Xamarin.PreBuilt.iOS 0x0000000100cfec2c xamarin_get_original_working_directory_path + 4356
54 Xamarin.PreBuilt.iOS 0x000000010105a07c AppleCryptoNative_X509ImportCollection + 3073984
55 libdyld.dylib 0x000000019a6992dc 322C4E05-D0CF-33F5-B996-CE5C67DF59B6 + 4828
'. Callstack: ' at CoreLocation.CLLocationManager.get_AuthorizationStatus() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/build/dotnet/ios/generated-sources/CoreLocation/CLLocationManager.g.cs:line 697
at Shiny.Locations.LocationExtensions.GetCurrentStatus(CLLocationManager locationManager, Boolean background)
at Shiny.Locations.LocationExtensions.RequestAccess(CLLocationManager locationManager, Boolean background)
at MSS.App.Views.Pages.Patrol.PatrolPage.CheckAccess() in C:\Projects\Git\MSS.App\MSS.App\Views\Pages\Patrol\PatrolPage.xaml.cs:line 74
at MSS.App.ViewModels.MainMenuPageViewModel.<Update>b__5_0(ModuleModel selectedModule) in C:\Projects\Git\MSS.App\MSS.App\ViewModels\MainMenuPageViewModel.cs:line 59
at System.Threading.Tasks.Task.<>c.<ThrowAsync>b__128_0(Object state)
at Foundation.NSAsyncSynchronizationContextDispatcher.Apply() in /Users/builder/azdo/_work/1/s/xamarin-macios/src/Foundation/NSAction.cs:line 179
at UIKit.UIApplication.UIApplicationMain(Int32 argc, String[] argv, IntPtr principalClassName, IntPtr delegateClassName) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 61
at UIKit.UIApplication.Main(String[] args, Type principalClass, Type delegateClass) in /Users/builder/azdo/_work/1/s/xamarin-macios/src/UIKit/UIApplication.cs:line 96
at MSS.App.Program.Main(String[] args) in C:\Projects\Git\MSS.App\MSS.App\Platforms\iOS\Program.cs:line 13
at System.Reflection.MethodBaseInvoker.InterpretedInvoke_Method(Object obj, IntPtr* args)
at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)'
Upvotes: 1
Views: 37
Reputation: 64995
This appears to be a bug in the Shiny NuGet package.
The iOS code crashes checking the authorization status. There are two variations on this API, one that works on iOS 14.0+ and the other on 4.2-13.x. (See below.) It appears that the Shiny is incorrectly calling the new API introduced in 14.0 even when the iOS version is 13.5. They will need to fix that code.
You may want to open an issue in the Github repo here: https://github.com/shinyorg/shiny and reference this analysis.
I had a poke around in their source code, but I couldn't quickly find where they are making the iOS call that causes the crash. If somebody can find that, then the fix should be trivial to make.
@available(iOS 14.0, *)
open var authorizationStatus: CLAuthorizationStatus { get }
/*
* authorizationStatus
*
* Discussion:
* Deprecated. Use the instance property authorizationStatus instead.
*/
@available(iOS, introduced: 4.2, deprecated: 14.0)
open class func authorizationStatus() -> CLAuthorizationStatus
Upvotes: 1