Turn Your iOS Device or Mac Into a Beacon
Although third-party manufactures can create Bluetooth low energy beacons by programming the beacon’s identity values into the hardware itself, any iOS device or Mac that supports sharing data using Bluetooth low energy can be used as a beacon.
Because turning your iOS device or Mac into a beacon requires the use of the Core Bluetooth framework, be sure to link your app to
CoreBluetooth.framework in your Xcode project. To access the classes and headers of the framework, include an #import <CoreBluetooth/CoreBluetooth.h> statement at the top of any relevant source files.Creating and Advertising a Beacon Region
To use your device as a beacon, you first need to generate a 128-bit UUID that you can use as your beacon region’s proximity UUID. Use the OS X command-line utility
uuidgen to easily generate 128-bit UUIDs. To do so, open a window in Terminal. Next type uuidgen on the command line to receive a unique 128-bit value in the form of an ASCII string that is punctuated by hyphens, as in the following example:$ uuidgen |
39ED98FF-2900-441A-802F-9C398FC199D2 |
Next, create a beacon region using the UUID you generated for the beacon’s proximity UUID, defining the major and minor values as needed. Be sure to also use a unique string identifier for the new region. The following code shows how to create a new beacon region using the example UUID above.
NSUUID *proximityUUID = [[NSUUID alloc] |
initWithUUIDString:@"39ED98FF-2900-441A-802F-9C398FC199D2"]; |
// Create the beacon region. |
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] |
initWithProximityUUID:proximityUUID |
identifier:@"com.mycompany.myregion" |
コメント
コメントを投稿