(reprint) IOS7 ibeacons Quest

Source: Internet
Author: User

Learning Ibeacons recently discovered that this thing has the potential to improve many of our user experiences in our lives in the future. IBeacons is an RFID-like micro-positioning technology introduced by the IOS7 system. Use Bluetooth 4.0 (Low power Bluetooth) for data transfer (iphone 4s + devices). Handheld devices can receive signals from Ibecons base stations within a certain range (up to 50m). Any Bluetooth device that implements the Ibeacon protocol can act as a ibeacon base station. Different other uses GPS, cellular data and other positioning methods. Bluetooth 4.0 itself is low cost, equipment power consumption is also low, so compared to other positioning methods have their own advantages. And this positioning is directly end-to-end direct positioning, eliminating the GPS satellite and cellular data base station communication, is an effective complement to the existing positioning technology, has its unique use of the scene and value.

ibeacons Development

Beacon Broadcasting

All Bluetooth 4.0-enabled idevice are capable of transmitting signals as beacon base stations, which requires corebluetooth.framework support. We need to create a Cbperipheralmanager instance and then launch Beacon Broadcast signal:

A beacon base station has three main properties, that is said above: Proximityuuid, Major, minor, corresponding to the Clbeacon class in Corelocation:

 
    1. @interface Clbeacon:nsobject <nscopying, nssecurecoding>
    2. //...
    3. @property (readonly, nonatomic) Nsuuid *proximityuuid;
    4. @property (readonly, nonatomic) NSNumber *major;
    5. @property (readonly, nonatomic) NSNumber *minor;
    6. //...
    7. @end

Create a unique marker for Beacon base Station

 
  1. time_t t;

    Srand ((unsigned) time (&t));

    Clbeaconregion *region = [[clbeaconregion alloc] initwithproximityuuid:self. Beaconregion. Proximityuuid

    Major:rand ()

    Minor:rand ()

    identifier: Self. Beaconregion. identifier];

Proximityuuid: This is the only one for each company. All ibeacons of the company have the same UUID.

Major: A series of related ibeacons signs.

Minor: An indication of a particular ibeacon.

Identifier: The only indication of the beacons area.

For example: An exhibition company A, and an exhibition company B will have different Proximityuuid, exhibition company A at address C and address d have different exhibition halls, then they have different major values. There will be different minor values for the different floors in the exhibition hall of address C. So we can uniquely determine a ibeacon based on the Proximityuuid,major,minor three values.

Get signal information for this beacon area

 
    1. Nsdictionary *peripheraldata = [Region Peripheraldatawithmeasuredpower:nil];
    2. Create and broadcast beacon signals

 
    1. Cbperipheralmanager *Peripheralmanager = [[Cbperipheralmanager alloc] initwithdelegate:self queue:dispatch_get_  Main_queue ()];
    2. [Peripheralmanager Startadvertising:peripheraldata];

Of course you also need to be in Cbperipheralmanagerdelegate Agent method: Peripheralmanagerdidupdatestate: Do some processing according to the different state.

Beacon Monitoring

Apple put the ibeacons related interface into the corelocation.framework. Before iOS7, we could define a geographic area through Clregion to track the movement of the device within that area, and after IOS7, Clregion was completely transformed into an abstract class Subclasses Clcircularregion and clbeaconregion respectively assume the function of realizing a geographical region and beacon signal region.

That is, after the iOS7, the clregion has two main attributes:

 
    1. @interface Clregion:nsobject <nscopying, nssecurecoding>
    2. @property (nonatomic, assign) BOOL notifyonentry;
    3. @property (nonatomic, assign) BOOL notifyonexit;
    4. @end

Notifyonentry and Notifyonexit respectively mark whether to invoke the proxy method when entering and exiting the zone. Clbeaconregion also adds an attribute Notifyentrystateondisplay flag to invoke the proxy method when the user's phone screen is lit.

To create a clbeaconregion, we need to create a unique UUID for the target monitoring area (the UUID needs to be consistent with the previous base station's UUID):

 
    1. Clbeaconregion *targetbeaconregion = [[Clbeaconregion alloc] Initwithproximityuuid:

      Self. Beaconregion. Proximityuuid

      Identifier: Self. Beaconregion.  identifier];

After Regoin is created, we need to monitor the region for information such as whether to enter the area and some distance, we need to create an Cllocationmanager instance and then call Startmonitoringforregion: method to monitor the above beaconregion:


    1. Self.locationmanager = [[Cllocationmanager alloc] init];
    2. Self.locationManager.delegate = self ;
    3. [Self.locationmanager startmonitoringforregion:targetbeaconregion];

All that is left is to get all the Clbeacon base stations in the monitoring area through the various methods in the Cllocationmanagerdelegate, to enter or exit a beacon area, to calculate the distance of a clbeacon, for example.

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.