本文介绍了将Macbook变成iBeacon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以将iOS设备变成iBeacons( iOS7设备充当iBeacon?).不幸的是,我只有一个设备,信标还没有到.因此,我想知道如何将MacBook Air(2011年中,确实支持蓝牙4.0)变成iBeacon以进行测试.是否有可用的现成应用程序,例如iOS的airlocate?预先感谢!

I know that I can turn iOS devices into iBeacons (Can an iOS7 device act as an iBeacon?). Unfortunately, I only have one device and my beacons have not arrived yet. So I was wondering how I could turn my MacBook Air (Mid-2011, does support Bluetooth 4.0) into an iBeacon for testing purposes. Are there any ready-made applications available like the airlocate for iOS? Thanks in advance!

推荐答案

注意:这仅适用于小牛,不适用于优胜美地.

Mavericks在Core Location中没有添加到iOS 7的iBeacon支持.但是,Mavericks现在可以充当BLE外围设备.鉴于iBeacon基本上是外围设备,应该可以(确实有可能)使用Mavericks作为iBeacon.

Mavericks doesn't have the iBeacon support in Core Location that was added to iOS 7. However, Mavericks does now have the ability to act as an BLE peripheral device. Given that an iBeacon is basically a peripheral it should be (and indeed is) possible to use Mavericks as an iBeacon.

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

In order to create an iBeacon on iOS you first create a CLBeaconRegion object and then use the peripheralDataWithMeasuredPower: method to get an NSDictionary containing the necessary advertisement data to broadcast. If you take the contents of this NSDictionary from an iOS device and use it on Mavericks then you get an iBeacon.

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

I have created a class to make this easier and allow you to generate the advertisement data dictionary directly on Mavericks. The source code is available at https://github.com/mttrb/BeaconOSX

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

The BLCBeaconAdvertisementData class take the proximityUUID, major, minor and calibrated power values and creates an NSDictionary that can be passed to the startAdvertising: method of CBPeripheralManager on Mavericks.

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

The BLCBeaconAdvertisementData class is quite simple. The main work is done by the following method:

- (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/

这篇关于将Macbook变成iBeacon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 13:53