在Xamarin应用程序上,我启动带有广告的GATT服务器,其中包含服务数据。这在Android上运行良好,在扫描过程中我可以从客户端(Android和iOS)读取数据。这是完成任务的代码(字节包含我的数据值):
var data = new AdvertiseData.Builder()
.SetIncludeDeviceName(false)
.AddServiceData(new Android.OS.ParcelUuid(Java.Util.UUID.FromString(SecurityUuid.Service)), bytes)
.Build();
Advertiser.StartAdvertising(settings, data, AdvertiseCallbacks);
我现在正在iOS上实现此部分,但是我不知道如何包含服务数据。我发现的唯一方法是在其中存储值但不符合我的需要的地方添加一个新特性,因为我需要在不连接服务的情况下而是在扫描期间读取该值。
这是我在iOS上开始投放广告的代码:
var data = new NSDictionary(
new NSString(SecurityUuid.Service),
NSObject.FromObject(value));
var advertisingData = new NSDictionary(
CBAdvertisement.DataLocalNameKey,
new NSString("test"),
CBAdvertisement.DataServiceUUIDsKey,
NSObject.FromObject(arry),
CBAdvertisement.DataServiceDataKey,
data
);
_peripheralManager.StartAdvertising(advertisingData);
Apple的官方文档说,我只能使用CBAdvertisement.DataLocalNameKey和CBAdvertisement.DataServiceUUIDsKey来启动广告。我尝试添加CBAdvertisement.DataServiceDataKey值(因为我从客户端读取了此内容,以便从Android广告中获得设置的值),但是它不起作用。
有什么建议吗?