1

当我尝试运行我的“xcode”项目时遇到了一些问题,我收到了这个“运行时”错误。

Assertion failure in -[CLLocationManager startRangingBeaconsInRegion:], /SourceCache/CoreLocationFramework/CoreLocation-1613.35/Framework/CoreLocation/CLLocationManager.m:991
2014-05-11 15:47:15.483 Ziew[1516:60b] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: region != nil'

我正在尝试使用“Estimote SDK”来使用接近应用程序代码示例构建类似的应用程序。原始示例效果很好,添加他们的代码时我没有更改任何内容。这是我的一些方法:

- (id)initWithBeacon:(ESTBeacon *)beacon
{
    self = [super init];
    if (self)
    {
        self.beacon = beacon;
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [[UITabBar appearance] setSelectedImageTintColor:[UIColor colorWithRed:(141/255.0) green:(198/255.0) blue:(63/255.0) alpha:1]];
    // Do any additional setup after loading the view.

    //Beacon Manager setup
    self.beaconManager = [[ESTBeaconManager alloc] init];
    self.beaconManager.delegate = self;

    self.beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:self.beacon.proximityUUID
                                                                 major:[self.beacon.major unsignedIntValue]
                                                                 minor:[self.beacon.minor unsignedIntValue]
                                                            identifier:@"RegionIdentifier"];
    [self.beaconManager startRangingBeaconsInRegion:self.beaconRegion];
}

#pragma mark - ESTBeaconManager delegate

- (void)beaconManager:(ESTBeaconManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(ESTBeaconRegion *)region
{
    if (beacons.count > 0)
    {
        ESTBeacon *firstBeacon = [beacons firstObject];
        [self textForProximity:firstBeacon.proximity];
    }
    NSLog(@"No beacons within region");
}

#pragma mark -

- (void)textForProximity:(CLProximity)proximity
{
    switch (proximity) {
        case CLProximityFar:
             NSLog(@"Far");
            break;
        case CLProximityNear:
            NSLog(@"Near");
            break;
        case CLProximityImmediate:
            NSLog(@"Immediate");
            break;

        default:
            NSLog(@"Unknown");
            break;
    }
}

- (void)viewDidDisappear:(BOOL)animated
{
    [self.beaconManager stopRangingBeaconsInRegion:self.beaconRegion];

    [super viewDidDisappear:animated];
}

我错过了什么?

解决方案

感谢所有回复的人。使用 Estimote SDK,您可以分配一个常量 UUID 和信标对应的主要和次要 id,以调用 startRangingBeaconsInRegion 方法。

self.beaconRegion = [[ESTBeaconRegion alloc] initWithProximityUUID:ESTIMOTE_PROXIMITY_UUID
                                                                 major:your_major_id
                                                                 minor:your_minor_id
                                                            identifier:@"RegionIdentifier"];
4

2 回答 2

2

据我所知,当您告诉它开始测距信标时,您的信标区域为零。由于您为您的属性分配了一个区域的初始化实例,因此您的属性声明可能被列为弱而不是强?

于 2014-05-11T22:19:21.147 回答
1

您可能已经从他们的演示中复制了 initWithBeacon 构造函数,并且在实例化视图控制器时(如从 xib 或情节提要)没有调用此构造函数。

因为 self.beacon 是 nil,所以构造的 ESTRegion 对象被分配了 nil 参数,这会导致崩溃。

你需要:

  • 首先是您周围的信标范围

或者

  • 在您的应用程序中硬编码信标标识符(或从某处获取)
于 2014-05-13T18:49:19.740 回答