BluetoothLE MacOS / iOS Not Scanning when Not Set Up for Background Bluetooth #1215
Unanswered
TPitman-mindfiretechnology
asked this question in
Q&A
Replies: 2 comments 2 replies
-
The beta is taking issues, but I need reproducible samples via the issue template so I have all of the questions answered. Background processing is needed if you use BleDelegate. I don't know if you're using this which is why I need reproducible samples please |
Beta Was this translation helpful? Give feedback.
0 replies
-
You said that beta is taking issues. I think that means I need to post an issue in the beta somewhere. In order to make sure I post the issue in the right place, can you tell me exactly where to post my issue please? Do I just post an issue in the main repo for shinyorg/shiny? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I don't know if QA is allowed for beta version or not. If not, then I apologize for posting this.
I have a new MAUI app (thus using the beta version of Shiny). When I ran the app on Android everything worked as expected. I was able to scan for devices and get the scan results.
I was having trouble getting it to scan bluetooth devices on iOS. I never got any scan results even though the app did ask for permissions, so I downloaded the source and have been looking into it.
I ran the example project and it was able to scan on both MacOS and iOS, so I dug deeper.
What I found was that the example app is set up for background bluetooth processing.
Since I do not want that feature in my app, I didn't set my app up for background processing.
As I debugged into it I found these lines of code in the BleManager class for Apple:
if (this.manager == null)
{
if (!AppleExtensions.HasPlistValue("NSBluetoothPeripheralUsageDescription"))
this.logger.LogCritical("NSBluetoothPeripheralUsageDescription needs to be set - you will likely experience a native crash after this log");
` if (!AppleExtensions.HasPlistValue("NSBluetoothAlwaysUsageDescription", 13))` ` this.logger.LogCritical("NSBluetoothAlwaysUsageDescription needs to be set - you will likely experience a native crash after this log");`
var background = this.services.GetService(typeof(IBleDelegate)) != null;
if (!background)
return new CBCentralManager(this, null);
` var opts = new CBCentralInitOptions` ` {` ` ShowPowerAlert = this.config.ShowPowerAlert,` ` RestoreIdentifier = this.config.RestoreIdentifier ?? "shinyble"` ` };`
this.manager = new CBCentralManager(this, null, opts);
this.manager.Delegate = this;
}
return this.manager;
I do know a fair bit about bluetooth on Apple products, but don't claim to be an expert of anything. I do know that you have to have a CBCentralManagerDelegate to receive bluetooth events.
I could see that the Shiny BleManager is derived from the CBCentralManagerDelegate.
I am sure I am not understanding something, but I decided as a test to change these lines:
if (!background)
return new CBCentralManager(this, null);
To this:
if (!background)
{
this.manager = new CBCentralManager(this, null);
this.manager.Delegate = this;
return this.manager;
}
And now my app works fine.
I am not 100% sure why that works, but it does. I can see in the return new CBCentralManger that the BleManager is returned as the delegate so in theory it should call the DiscoveredPeripheral callback on BleManager when a scan result is found, but for some reason it doesn't.
I am sure I am missing something and that this change shouldn't be needed. Can someone help me understand what I forgot to do to set things up? I followed the "ugly, but effective boilerplate builder" (readme.md's word on github, not mine.)
Thank you!
Beta Was this translation helpful? Give feedback.
All reactions