CLRegionState UnKnown When I'm in the Region

I am testing iBeacon, I used the method didDetermineState:, and CLRegionState- CLRegionStateUnknownwhen I am inside the region, can someone tell me why?

My Bluetooth is turned on and detects beacons when I have their range for CLBeaconStateUnknown, the sender and receiver are in the range (1 Meter), here is my implementation

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

    switch (state) {
    case CLRegionStateInside:
        currentBeconRegion = (CLBeaconRegion *)region;
        [self.locationManager startRangingBeaconsInRegion:currentBeconRegion];
        NSLog(@"INSIDE the Region");//not logging
        break;
    case CLRegionStateOutside:
        NSLog(@"OUTSIDE the Region");
        break;
    case CLRegionStateUnknown:
    default:
        NSLog(@"Region state UNKNOWN!!!"); //Logging on console
        statusLabel.text = @"Region state UNKNOWN!!!";
    //[self.locationManager stopRangingBeaconsInRegion:beaconRegion];           
    [self.locationManager startRangingBeaconsInRegion:beaconRegion];//Suceessfully ranging the beacon

        break;
    }
}
+3
source share
4 answers

I restarted both my devices and reinstalled the application, still encountering the same problem, and also did not shoot didEnterRegion:and didExitRegion:.

- (void)viewDidLoad
 {

 [super viewDidLoad];    
//set peripheralManager delegate
self.peripheralManager = [[CBPeripheralManager alloc] initWithDelegate:self
                                                                 queue:nil
                                                               options:nil];


//Set location managaer delegate
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;


uuid = [[NSUUID alloc] initWithUUIDString:@"E01D235B-A5DB-4717-8D2F-28D5B48931F1"];

// Setup a new region with that UUID and same identifier as the broadcasting beacon
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"testRegion"];
self.beaconRegion.notifyEntryStateOnDisplay = YES;
self.beaconRegion.notifyOnEntry = YES;
self.beaconRegion.notifyOnExit = YES;

}


#pragma mark -
#pragma mark - Peripheral Manager Delegates

-(void)peripheralManagerDidUpdateState:(CBPeripheralManager *)peripheral
{
switch (peripheral.state) {
    case CBPeripheralManagerStatePoweredOn:
        [self.locationManager startMonitoringForRegion:self.beaconRegion];
        break;
    case CBPeripheralManagerStatePoweredOff:
         statusLabel.text = @"Bluetooth is Off";
        [self clearFileds];
        [self.locationManager stopMonitoringForRegion:self.beaconRegion];
        break;
    case CBPeripheralManagerStateUnknown:
    default:
        statusLabel.text = @"Bluetooth is Unsupported";
        [self clearFileds];
        [self.locationManager stopMonitoringForRegion:self.beaconRegion];
        break;
   }

 }

#pragma mark -
#pragma mark - Location Manager Delecate Methods

-(void)locationManager:(CLLocationManager *)manager didStartMonitoringForRegion:(CLRegion *)region
{

[self.locationManager requestStateForRegion:self.beaconRegion];

}

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

switch (state) {
    case CLRegionStateInside:
        currentBeconRegion = (CLBeaconRegion *)region;
        [self.locationManager startRangingBeaconsInRegion:currentBeconRegion];
        NSLog(@"INSIDE the Region");
        break;
    case CLRegionStateOutside:
        NSLog(@"OUTSIDE the Region");
        break;
    case CLRegionStateUnknown:
    default:
        NSLog(@"Region state UNKNOWN!!!");
        statusLabel.text = @"Region state UNKNOWN!!!";
       [self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
        break;
    }
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
//check if we're ranging the correct beacon
if (![self.beaconRegion isEqual:region]) { return;}

NSLog(@"didEnterRegion");
if([region isKindOfClass:[CLBeaconRegion class]])
{
    currentBeconRegion = (CLBeaconRegion *)region;
    if ([beaconRegion.identifier isEqualToString:@"testRegion"])
    {

        //send local notificaation
        UILocalNotification *notice = [[UILocalNotification alloc] init];
        notice.alertBody = @"Becoan Found!!!";
        notice.alertAction =@"View";
        [[UIApplication sharedApplication] presentLocalNotificationNow:notice];

        //srart raning beacon region
        [self.locationManager startRangingBeaconsInRegion:currentBeconRegion];


        }
    } 

 }
 -(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{

if ([beacons count] > 0) {

    int major = [beacons.firstObject major].intValue;
    int minor = [beacons.firstObject minor].intValue;

    if (major != self.foundBeacon.major.intValue || minor !=     self.foundBeacon.minor.intValue) {
        NSLog(@"Found Beacon is: %@", [beacons firstObject]);
    }

    self.foundBeacon = [[CLBeacon alloc] init];
    self.foundBeacon = [beacons firstObject];
    //Set the ui
    [self setFileds];

 }
else //[beacon count]  0
{
    statusLabel.text = @"No becaons found";
    [self clearsFileds];
   // [self.locationManager stopMonitoringForRegion:beaconRegion];
    }

}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
NSLog(@"didExitRegion");
if([region isKindOfClass:[CLBeaconRegion class]])
{
    currentBeconRegion = (CLBeaconRegion *)region;
    if ([beaconRegion.identifier isEqualToString:@"testRegion"])
    {
        [self.locationManager stopMonitoringForRegion:currentBeconRegion];

     }
  }
}
+1
source

, " ", , iBeacon ? Bluetooth ? ?

iBeacon , , iBeacon. , , , , , iBeacon.proximity CLProximityUnknown - .

didDetermineState , ( , notifyEntryStateOnDisplay=YES ). , , CLRegionStateUnknown. , , , . . , !

+1

iOS 8, :

, - , . 4 , , , .

TL;DR

,

+1
source

I had the same problem before and the answer was: I just forgot to call:

[self.locationManager startMonitoringForRegion:beaconRegion];

At first, I mistakenly suggested that if you start to hesitate:

[self.locationManager startRangingBeaconsInRegion:beaconRegion];

... and getting data for rssi, accuracy and UUID in the method locationManager:didRangeBeacons:inRegion:, CLLocationManager should be able to find out that the phone is in this region, but apparently not. Therefore, when querying the state using:

[self.locationManager requestStateForRegion:beaconRegion];

I got CLRegionStateUnknownfor this area in locationManager:didDetermineState:forRegion:, like you.

0
source

All Articles