0

我正在尝试从触发 didEnterRegion 方法的信标中获取“主要”和“次要”ID。有人告诉我,我可以通过将测距和监控结合在一起来做到这一点,但我似乎无法让它正常工作。

我正在使用 Estimote 信标并正在使用 Estimote API。任何想法这里出了什么问题?谢谢!

这是一个链接,它说您可以将监控和测距结合起来:iBeacon:获取主要和次要 - 仅寻找 uuid

设置:

#import "ViewController.h"
#import "ESTBeaconManager.h"

@interface ViewController () <ESTBeaconManagerDelegate>

@property (nonatomic, strong) ESTBeaconManager* beaconManager;
@property (nonatomic, strong) UIImageView*      bgImageView;
@property (nonatomic, assign) BOOL              notificationShown;
@property (nonatomic, strong) UIImageView*      productImage;

@end

@implementation ViewController

ViewDidLoad:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.beaconManager = [[ESTBeaconManager alloc] init];
    self.beaconManager.delegate = self;
    self.beaconManager.avoidUnknownStateBeacons = YES;

    ESTBeaconRegion* region = [[ESTBeaconRegion alloc] 
    initRegionWithIdentifier:@"EstimoteSampleRegion"];

    [self.beaconManager startMonitoringForRegion:region];
    [self.beaconManager requestStateForRegion:region];
    [self.beaconManager startRangingBeaconsInRegion:region];

    [[NSUserDefaults standardUserDefaults] setObject:@"FALSE" 
    forKey:@"connectedToBeacon"];
    [[NSUserDefaults standardUserDefaults] synchronize];

}

DidRange信标:

-(void)beaconManager:(ESTBeaconManager *)manager
     didRangeBeacons:(NSArray *)beacons
            inRegion:(ESTBeaconRegion *)region {

    NSString *connectedToBeacon = [[NSUserDefaults standardUserDefaults] 
    stringForKey:@"connectedToBeacon"];

    if (connectedToBeacon == FALSE) {

        NSNumber *beaconMajor = region.major;
        NSNumber *beaconMinor = region.minor;

        NSString *alertText = [NSString stringWithFormat:@" Entering (%@,%@)", 
        beaconMajor, beaconMinor];

        UILocalNotification *notification = [[UILocalNotification alloc] init];
        notification.alertBody = alertText;
        notification.soundName = UILocalNotificationDefaultSoundName;

        [[UIApplication sharedApplication] presentLocalNotificationNow:notification];

        [[NSUserDefaults standardUserDefaults] setObject:@"TRUE" 
        forKey:@"connectedToBeacon"];
        [[NSUserDefaults standardUserDefaults] synchronize];

    }
}
4

1 回答 1

0

我还没有尝试过使用 Estimote 的框架。我一直在使用 Core Location 框架的 Core Location 管理器、CLBeaconRegion 和 CLBeacon 类,所以我的答案将基于此。

假设它们以相同的方式工作,信标测距调用会向您传递一个包含 1 个或多个信标的数组以及它们匹配的区域。

除非您使用这些值设置区域,否则该区域中的主要和次要版本值将为零。

但是,信标对象中的主要和次要值将包含您实际检测到的信标的主要和次要编号。如果您当前检测到多个,则必须提出选择一个的逻辑。我所做的是循环并选择最近的一个(使用准确性)谁的接近度是未知的。

(编辑以纠正一些错别字)

于 2013-12-02T03:47:14.717 回答