IBeacon Development notes and ibeacon Development notes

Source: Internet
Author: User

IBeacon Development notes and ibeacon Development notes

IBeacon Development notes

 

2015.10.19

Airlocate

==========

Airlocate shows how to use this monitoring range clbeaconregions.

The Code also provides an example of how you can calibrate and configure iOS devices as beacon corebluetooth.

You can configure an iOS device as a beacon as follows:

1) get two iOS devices equipped with Bluetooth LE. One will be the target device and the other will be a remote (calibrated) device.

2) load and start the application on these two devices.

3) switch the target device to a beacon by selecting configuration and enabling.

4) Take the calibration device and move the target device one meter away.

5) Select the calibration process on the calibration device.

6) select the target device from the table view.

7) The calibration process will begin. You should be in this process, in this process, the wave of the calibration device from one side to the other side.

8) When the calibration process is complete, it displays a calibrated bounce value on the screen.

9) return to the configuration screen on the target device and enter the value at the measured power.

Note: The calibration process is optional, but it is recommended that you fine tune the scope for your environment.

You can configure an iOS device without calibration it does not specify the measurement power beacon.

If no measurement power is specified, CoreLocation is a predetermined value by default.

Once you set your target device as a beacon, you can use this application to demonstrate beacon range and monitoring.

To demonstrate the range, select a remote device. Alrangingviewcontroller has a set of clbeaconregions.

To demonstrate monitoring, select remote device monitoring. Almonitoringviewcontroller allows you to configure a clbeaconregion monitoring.

Copyright (2013) Apple reserves all rights.

0. Write in front

Test: We recommend that you download the Estimote app as the base station and obtain its UUID, majon, and minor parameters.

About devices: iBeacon Uses Bluetooth LE technology, so you must have an iOS device with built-in low-power Bluetooth to work with iBeacon. The list contains the following devices:

  • IPhone 4S or newer
  • Third-generation iPad or newer
  • IPad mini or updated
  • Fifth-generation iPod touch or updated
  • System version 7.0 or later

Test results: the signal of the received signal is mild to-90, and the valid distance is about 30 m.

Purpose: Bluetooth BLE, positioning, smart home, etc. I also made an app for punching in at work. Only within the valid range can I be successful.

UUID, Primary, Secondary identifier

If you are not familiar with iBeacon, you may not be familiar with the terminology.UUID,Main value (major value)AndMinor value).

An iBeacon is nothing but a low-power bluetooth device. It publishes information in a specific structure. These specific things are beyond the scope of this tutorial, but one important thing to understand is that iOS is able to monitor these iBeacon based onUUID,Main ValueAndSecondary Value.

UUDID is the abbreviation of Universally Unique Identifier (universal Unique Identifier). It is actually a random string;B558CBDA-4472-4211-A350-FF1196FFE8C8This is an example. In the scope of iBeacon's discussion, a UUID is usually used to indicate your top-level identity. As a developer, If you generate a UUID and allocate it to your iBeacon device, when a device detects your iBeacon, it will know which iBeacon it is communicating.

The primary value and secondary value provide a slightly higher granularity than the UUID. These values are only 16-bit unsigned integers that can identify each individual iBeacon, or even those with the same UUID.

For example, if you have multiple department stores, all your iBeacon transmitters can have the same UUID, but each store has its own main value, each department has its own secondary value. Your application can respond to iBeacon in the footwear Department of your Miami and Florida stores.

I. Use of iBeacon

Start listening to your Ibeacon.

In iOS 8, Apple changed its position in the enabling mode (iBeacon is based on Bluetooth and positioning), first in the project info. add the NSLocationAlwaysUsageDescription field to plist (This field allows running in the background all the time)

Maybe you may be surprised that iBeacon is related to Core Location. After all, it is a bluetooth device, but it is not surprising that iBeacon provides macro positioning information corresponding to GPS. When programming an iOS device as an iBeacon, you need to use the Core Bluetooth framework. When monitoring iBeacon, you only need to deal with the Core Location.

When the program runs, you will find that there is your program icon in the lower left corner of the device.

. H file

# Import <UIKit/UIKit. h>

# Import <CoreLocation/CoreLocation. h>

@ Interface ViewController: UIViewController <UITableViewDataSource, UITableViewDelegate, CLLocationManagerDelegate>

@ Property (nonatomic, strong) NSArray * beaconArr; // stores the scanned iBeacon

@ Property (strong, nonatomic) CLBeaconRegion * beacon1; // The iBeacon to be scanned

@ Property (strong, nonatomic) CLLocationManager * locationmanager;

@ End

. M file

# Define BEACONUUID @ "12334566-7173-4889-9579-954995439125" // you can replace the uuid of your device with the uuid of your device.

-(Void) viewDidLoad {

[Super viewDidLoad];

Self. tableView = [[UITableView alloc] initWithFrame: CGRectMake (0, 20,320,568)];

Self. tableView. delegate = self;

Self. tableView. dataSource = self;

[Self. view addSubview: self. tableView];

Self. beaconArr = [[NSArray alloc] init];

Self. locationmanager = [[CLLocationManager alloc] init]; // Initialization

Self. locationmanager. delegate = self;

Self. beacon1 = [[CLBeaconRegion alloc] initWithProximityUUID: [[NSUUID alloc] initWithUUIDString: BEACONUUID] identifier: @ "media"]; // initialize iBeacon information for monitoring

[Self. locationmanager requestAlwaysAuthorization]; // set location to always allow

}

-(Void) locationManager :( CLLocationManager *) manager didChangeAuthorizationStatus :( clthorizationstatus) status {

If (status = kclthorizationstatusauthorizedalways ){

[Self. locationmanager startMonitoringForRegion: self. beacon1]; // start MonitoringiBeacon

}

}

{

// IBeacon found to enter the monitoring Scope

-(Void) locationManager :( CLLocationManager *) manager didEnterRegion :( CLRegion *) region {

[Self. locationmanager startRangingBeaconsInRegion: self. beacon1]; // start RegionBeacons

}

// Scan the iBeacon information.

-(Void) locationManager :( CLLocationManager *) manager didRangeBeacons :( NSArray *) beacons inRegion :( CLBeaconRegion *) region {

// If there is an iBeacon we want to monitor, stop scanning it.

If (! [[Region. proximityUUID UUIDString] isw.tostring: BEACONUUID]) {

[Self. locationmanager stopMonitoringForRegion: region];

[Self. locationmanager stopRangingBeaconsInRegion: region];

}

// Print all iBeacon Information

For (CLBeacon * beacon in beacons ){

NSLog (@ "Arg is: % ld", beacon. Arg );

NSLog (@ "beacon. proximity % ld", beacon. proximity );

......

}

Self. beaconArr = beacons;

[Self. tableView reloadData];

}

 

-(NSInteger) tableView :( UITableView *) tableView numberOfRowsInSection :( NSInteger) section

{

Return self. beaconArr. count;

}

-(UITableViewCell *) tableView :( UITableView *) tableView cellForRowAtIndexPath :( NSIndexPath *) indexPath

{

Static NSString * ident = @ "cell ";

UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier: ident];

If (! Cell ){

Cell = [[UITableViewCell alloc] initWithStyle: UITableViewCellStyleSubtitle reuseIdentifier: ident];

}

CLBeacon * beacon = [self. beaconArr objectAtIndex: indexPath. row];

Cell. textLabel. text = [beacon. proximityUUID uuuidstring];

NSString * str;

Switch (beacon. proximity ){

Case CLProximityNear:

Str = @ "near ";

Break;

Case CLProximityImmediate:

Str = @ "Super near ";

Break;

Case CLProximityFar:

Str = @ "far ";

Break;

Case CLProximityUnknown:

Str = @ "no ";

Break;

Default:

Break;

}

Cell. detailTextLabel. text = [NSString stringWithFormat: @ "% @ % ld % @", str, beacon. ARG, beacon. major, beacon. minor];

Return cell;

}

// Handle some errors. Because you are dealing with very specific hardware features, you need to know the monitoring and ranging failures caused by any reason.

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error {    NSLog(@"Failed monitoring region: %@", error);}- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {    NSLog(@"Location manager failed: %@", error);}
Ii. ibeacon Parameters

Uuid uniquely identifies this type of iBeacon.

Proximity: Near (within a few meters), Immediate (within several centimeters), and Far (more than 10 meters away, but far is more than 10 meters in the test ), unknown (invalid)

After major and minor are combined, the iBeacon of the same type is distinguished.

Distance between accuracy and iBeacon

If the received signal is mild to negative, the closer the signal is to 0, the stronger the signal. If the signal is equal to 0, the signal strength cannot be obtained.

 

3. Notification

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {    if ([region isKindOfClass:[CLBeaconRegion class]]) {        UILocalNotification *notification = [[UILocalNotification alloc] init];        notification.alertBody = @"Are you forgetting something?";        notification.soundName = @"Default";        [[UIApplication sharedApplication] presentLocalNotificationNow:notification];    }}

Your location manager will call the above method when you leave a region, which is a useful time for this application. You don't need to be notified when you are close to your laptop package, but you only need to be notified when you leave it too far.

Check whether the region isCLBeaconRegionBecause if you are also performing geographic location area monitoring, it may also beCLCircularRegion. Then you will send a local notification with the message "Are you forgetting something ?" .

Compile and run your application; leave a registered iBeacon, and once you leave far enough, you will see the notification pop-up.

 

Reference: https://github.com/nixzhu/dev-blog/blob/master/2014-04-23-ios7-ibeacons-tutorial.md

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.