question

GiovanniMauramati-0639 avatar image
0 Votes"
GiovanniMauramati-0639 asked RobCaplan edited

BLE Gatt Server for iOS in Xamarin.Forms

Hi all,
I'm new to mobile development and Xamarin... so be patient with my obvious questions, please :)
I'm developing an Xamarin.Forms app and I would like to start an BLE Advertisement (acting iOS as a peripheral).
I understood that I have to move on .iOS project in my solution and write code there. So I created a simple class with a unique void to start advertising. After that I instantiate the class in AppDelegate.cs and call the void.
Everything seems to work (I have no errors) but the peripheral manager state is always "unkonwn". I searched on the web and I understood that could be an issue related to something called "objective c binding", so I added an interface and "exported" the main void... with no luck... tha state is always unknown.

Someone can help me, please?

Thank you so much everybody!

 using CoreBluetooth;
 using Foundation;
 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using UIKit;
    
 namespace Blux.iOS
 {
     public interface IBleGattServerManager
     {
         [Export("Init",ObjCRuntime.ArgumentSemantic.Strong)]
         void Init();
     }
     public class BleGattServerManager:IBleGattServerManager
     {
         [Export("Init")]
         public void Init()
         {
             CBPeripheralManager _PeripheralManager = new CBPeripheralManager();
    
             var uui = new CBUUID[] { CBUUID.FromString("625D74A2-3E61-4D1E-8949-8BE42DFDC6DA") };
             var nsArray = NSArray.FromObjects(uui);
             var nsObject = NSObject.FromObject(nsArray);
             var advertisementData = new NSDictionary(CBAdvertisement.DataLocalNameKey, "ciccio", CBAdvertisement.DataServiceUUIDsKey, nsObject);
             _PeripheralManager.StartAdvertising(advertisementData);
             Console.WriteLine("ciccio:" + _PeripheralManager.State.ToString());
         }
    
     }
 }
dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers