Estimote断言失败

时间:2014-05-11 20:52:50

标签: ios objective-c estimote

当我尝试运行“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”使用proximity application代码示例构建类似的应用程序。原始示例效果很好,当我添加代码时,我没有更改任何内容。这里有一些方法:

- (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,您可以使用信标对应的主要和次要ID分配常量UUID,以获取调用的startRangingBeaconsInRegion方法。

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

2 个答案:

答案 0 :(得分:2)

据我所知,当你告诉它开始测距信标时,你的灯塔区域是零。既然您为属性分配了一个区域的初始化实例,那么您的属性声明是否可以列为弱而不是强?

答案 1 :(得分:1)

您可能已从其演示中复制了initWithBeacon构造函数,并且在实例化视图控制器时未调用此构造函数(如来自xib或storyboard)。

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

你需要:

  • 首先围绕您的信标范围

  • 您应用中的硬编码信标标识符(或从某处获取)