I am building an iOS application with Xamarin, with this BLE plugin:
https://github.com/aritchie/bluetoothle
I just pass the UUID through BLE and it works. Here is my code:
var data = new Plugin.BluetoothLE.Server.AdvertisementData { LocalName = "MyServer", }; data.ServiceUuids.Add(new Guid("MY_UUID_HERE")); await this.server.Start(data);
The only problem is that it stops broadcasting when I put the application in the background. And resumes again when I open the application again.
How can I let him continue to broadcast it in the background? I read the documentation here:
https://developer.apple.com/library/content/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html
And it says that I have to use the CBCentralManager class to get the save and restore function (so I can always support broadcast UUIDs), but it's hard for me to translate this into Xamarin / C #.
EDIT
After exploring a few more, I read that I need to create an instance of CBCentralManager and implement WillRestoreState in the delegate. I did this in AppDelegate :
[Register("AppDelegate")] public class AppDelegate : MvxApplicationDelegate, ICBCentralManagerDelegate { private IGattServer server = CrossBleAdapter.Current.CreateGattServer(); private CBCentralManager cbCentralManager; public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions) {
But that didn't matter to me. And the WillRestoreState method WillRestoreState never called ... I don't mind using another plugin / library if I need at this point ...
EDIT 2
I just realized that the application is still broadcasting while it is in the background, I no longer see the UUID of the service (on the web portal of the beacon I'm testing with), I see only the phone identifier.