gpt4 book ai didi

macos - 将 Macbook 变成 iBeacon

转载 作者:行者123 更新时间:2023-12-03 07:41:05 25 4
gpt4 key购买 nike

我知道我可以将 iOS 设备变成 iBeacons ( Can an iOS7 device act as an iBeacon? )。不幸的是,我只有一台设备,我的信标还没有到达。所以我想知道如何将我的 MacBook Air(2011 年中,支持蓝牙 4.0)变成 iBeacon 进行测试。有没有现成的应用程序可供使用,例如适用于 iOS 的 Airlocate?提前致谢!

最佳答案

注意:这仅适用于 Mavericks,不适用于 Yosemite。

Mavericks 在 iOS 7 中添加的 Core Location 中不支持 iBeacon。但是,Mavericks 现在能够充当 BLE 外围设备。鉴于 iBeacon 基本上是一个外围设备,它应该(而且确实是)可以使用 Mavericks 作为 iBeacon。

为了在 iOS 上创建 iBeacon,您首先创建一个 CLBeaconRegion 对象,然后使用 peripheralDataWithMeasuredPower: 方法获取包含以下内容的 NSDictionary广播必要的广告数据。如果您从 iOS 设备获取此 NSDictionary 的内容并在 Mavericks 上使用它,那么您将获得一个 iBeacon。

我创建了一个类来简化此操作,并允许您直接在 Mavericks 上生成广告数据字典。源代码可在 https://github.com/mttrb/BeaconOSX 获取。

BLCBeaconAdvertisementData 类采用 proximityUUIDmajorminor 和校准功率值,并创建一个 NSDictionary可以传递给 Mavericks 上 CBPeripheralManagerstartAdvertising: 方法。

BLCBeaconAdvertisementData 类非常简单。主要工作是通过以下方法完成的:

- (NSDictionary *)beaconAdvertisement {
NSString *beaconKey = @"kCBAdvDataAppleBeaconKey";

unsigned char advertisementBytes[21] = {0};

[self.proximityUUID getUUIDBytes:(unsigned char *)&advertisementBytes];

advertisementBytes[16] = (unsigned char)(self.major >> 8);
advertisementBytes[17] = (unsigned char)(self.major & 255);

advertisementBytes[18] = (unsigned char)(self.minor >> 8);
advertisementBytes[19] = (unsigned char)(self.minor & 255);

advertisementBytes[20] = self.measuredPower;

NSMutableData *advertisement = [NSMutableData dataWithBytes:advertisementBytes length:21];

return [NSDictionary dictionaryWithObject:advertisement forKey:beaconKey];
}

我在 http://www.blendedcocoa.com/blog/2013/11/02/mavericks-as-an-ibeacon/ 上有一篇关于此问题的更详细的博客文章

关于macos - 将 Macbook 变成 iBeacon,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19410398/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com