CLBeacon - how to change rssi, major and minor?

2019-02-16 03:22发布

My question is basically - how do I get to modify iBeacon's default settings like major, minor and RSSI?

2条回答
家丑人穷心不美
2楼-- · 2019-02-16 03:59

When you initialize a CLBeaconRegion object you can specify Major and Minor variables. Took a look at initWithProximityUUID:major:minor:identifier method.

As far as am aware ones a beacon active your cannot change it value unless you recreate that object. Rssi represents signal strength of the beacon which is only read-only and depends on the environment.

Here the link for the (documentation](https://developer.apple.com/library/iOs/documentation/CoreLocation/Reference/CLBeaconRegion_class/Reference/Reference.html#//apple_ref/doc/uid/TP40013054)

查看更多
smile是对你的礼貌
3楼-- · 2019-02-16 04:05

There are different ways to set these values depending on what you mean by an iBeacon:

  1. Hardware iBeacons

    Each Beacon vendor has different ways of setting these values. Some are changed via a bluetooth service that is typically managed with a proprietary iOS or Android app. (Examples include Radius Networks' battery-powered and USB beacons and TwoCanoes beacons.) Radius Networks' PiBeacon includes an SD card with an editable file containing the identifiers. Other vendors like Estimote create beacons with fixed UUIDs that cannot be changed. Because there is no standard mechanism, there is no universal tool for setting identifiers on all beacon types.

  2. iOS Software iBeacons:

    You set these values with code like below:

    CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:@"2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"] major:1 minor:1 identifier:@"com.radiusnetworks.iBeaconExample"];
    NSDictionary *peripheralData = [region peripheralDataWithMeasuredPower:-55];
    [_peripheralManager startAdvertising:peripheralData];
    
  3. The iOS CLBeacon class

    The CLBeacon class is not designed to be created or modified by the user -- it is supposed to be constructed by CoreLocation when it detects iBeacons. That said, you can force writing to its read-only properties using KVO syntax like so:

    CLBeacon * iBeacon = [[CLBeacon alloc] init];
    [iBeacon setValue:[NSNumber numberWithInt:1] forKey:@"major"];
    [iBeacon setValue:[NSNumber numberWithInt:1] forKey:@"minor"];
    [iBeacon setValue:[NSNumber numberWithInt:-55] forKey:@"rssi"];
    [iBeacon setValue:[[NSUUID alloc] initWithUUIDString:@"2F234454-CF6D-4A0F-ADF2-F4911BA9FFA6"] forKey:@"proximityUUID"];
    NSLog(@"I constructed this iBeacon manually: %@", iBeacon);
    

    However, if you are forcing the CLBeacon class to be used in ways it was not designed to be used that might mean you are doing something wrong.

Full disclosure: I work for Radius Networks.

查看更多
登录 后发表回答