I'm having some problems when I try and run my "xcode" project and I get this "run time" error.

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'

I'm trying use the "Estimote SDK" to build a similar application using the proximity application code example. The original example works great and I didn't change anything when I added their code. Here some of my methods:

- (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];
}

What am I missing?

SOLUTION

Thank you to everyone who responded. Using the Estimote SDK you can assign a constant UUID with the beacon corresponding major and minor id to get the startRangingBeaconsInRegion method called.

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

解决方案

From what I can tell your beacon region is nil by the time you tell it to start ranging beacons. Since you assign to your property an initialized instance of a region, maybe your property declaration is listed as weak instead of strong?

其他提示

You have probably copied initWithBeacon constructor from their demos and this constructor is not being called when view controller is being instantiated (like from xib or storyboard).

Because self.beacon is nil, constructed ESTRegion object is allocated with nil params which causes crash.

You need to:

  • range for beacons around you first

or

  • hardcode beacon identifiers in your app (or fetch it from somewhere)
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top