iBeacon:获得主要和次要 - 只寻找uuid [英] iBeacon: get major and minor - only looking for uuid

查看:166
本文介绍了iBeacon:获得主要和次要 - 只寻找uuid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用air locate示例并仅通过uuid监控iBeacons。当我得到输入的区域事件时,如果我只是在寻找uuid,我似乎无法从触发事件的信标/区域获得主要和次要(如果我正在监视一个uuid,我可以指定的主要和次要) - 有没有人知道这样做的方法/我错过了什么?

I'm using the air locate example and monitoring for iBeacons by uuid only. When I get the entered region event, I can't seem to get the major and minor from the beacon/region that has triggered the event if I'm only looking for the uuid (I can if I'm monitoring for a uuid with specified major and minor) - does anyone know a way to do this/am I missing something?

我真的不想开始测距 - 看起来不像我应该... ..

I don't really want to start ranging - doesn't seem like I should need to..

(用例是说很多商店都带有相同uuid的信标,然后发出操作系统通知,其中包含有关该商店的相关信息(通过查询主要和次要获得))

(The use case is for say lots of stores all with beacons with the same uuid, then issuing an OS notification with relevant information about that store (obtained by querying the major and minor))

这基本上就是我做的事情:

Here's basically what I do:

CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
identifier:@"blah"];
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
region.notifyEntryStateOnDisplay = YES;

[self.locationManager startMonitoringForRegion:region];

然后在app delegate中:

Then in the app delegate:

- (void) locationManager:(CLocationManager*)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion*)region {

    // assume for now its the iBeacon
    CLBeaconRegion *beaconRegion = (CLBeaconRegion*) region;

    beaconRegion.major  // hasn't been set...

}

非常感谢!

推荐答案

你没有做错任何事。看起来令人惊讶,监控API没有为您提供触发区域更改的特定信标。

You're not doing anything wrong. Surprising as it may seem, the monitoring API doesn't give you the specific beacon(s) that triggered the region change.

未在CLBeaconRegion对象上设置major的原因是因为这是用于开始监视的完全相同的对象,并且您将该字段设置为nil(或没有设置它,留下它没有)。您正在寻找的是一个额外的CLBeacon对象数组。正如你的建议,这只出现在测距API上。

The reason the major isn't set on the CLBeaconRegion object is because that is the exact same object you used to start monitoring, and you set that field to nil (or didn't set it at all leaving it nil). What you are looking for is an additional array of CLBeacon objects. And as you suggest, this is only present on the Ranging APIs.

开始测量并不是什么大不了的事。只需在开始监控的同时进行设置:

It really isn't a big deal to start ranging. Just set it up at the exact same time as you start monitoring:

CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
identifier:@"blah"];
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
region.notifyEntryStateOnDisplay = YES;

[self.locationManager startMonitoringForRegion:region]; 
[self.locationManager startRangingBeaconsInRegion:region]; 

如果你只关心第一个调程,你可以使用一个标志来忽略进一步的更新:

And if you only care about the first ranging call, you can use a flag to ignore further updates:

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
    if (!_firstOneSeen) { 
        // Do something with beacons array here
    }
}

当您离开该区域时重置该标志

And reset that flag when you leave the region

- (void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
    _firstOneSeen = NO;
}

作为奖励,这也会使您的监控响应时间更快应用程序在前台。请参阅: http://developer.radiusnetworks.com/ 2013/11/13 / ibeacon-monitoring-in-the-background-and foreground.html

As a bonus, this will also make your monitoring response times much faster when your app is in the foreground. See: http://developer.radiusnetworks.com/2013/11/13/ibeacon-monitoring-in-the-background-and-foreground.html

这篇关于iBeacon:获得主要和次要 - 只寻找uuid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆