Beacon detection is taking a long time.
Reproduction instructions are available.
①Run self findBeacon;
to initiate detection
②Turn on the beacon
③
EnterRegion.CLRegionStateInside.
appears.
④FindBeacon. Beacon Detected
⑤Turn off the beacon
⑥
ExitRegion CLRegionStateOutside
appears after a while
⑦Turn on the beacon
It may take some time for EnterRegion. and CLRegionStateInside. to appear after this.
I'm trying iPhone 5 (iOS 8.4.1), but sometimes it takes about 30 seconds and sometimes it takes a couple of seconds.
It sometimes took more than 2 minutes for another device.
I'm having a hard time because the beacon doesn't seem to be detected unless it goes to EnterRegion.
Is there anything wrong with the implementation method?
Thank you for your cooperation.
- (void) findBeacon {
CLLocationManager* locationManager = [CLLocationManager new];
locationManager startMonitoringForRegion: beaconRegion;
}
- (void) locationManager: (CLLocationManager*) manager didStartMonitoringForRegion: (CLRegion*) region {
NSLog (@"startMonitoring");
manager requestStateForRegion:region;
}
- (void) locationManager: (CLLocationManager*) manager didDetermineState: (CLRegionState) state forRegion: (CLRegion*) region {
switch(state){
caseCLRegionStateInside:
NSLog (@"CLRegionStateInside");
CLBeaconRegion* beaconRegion=(CLBeaconRegion*)region;
manager startRangingBeaconsInRegion: beaconRegion;
break;
caseCLRegionStateOutside:
NSLog(@"CLRegionStateOutside");
break;
}
-(void) locationManager:(CLLocationManager*) manager didEnterRegion:(CLRegion*)region{
NSLog(@"EnterRegion.");
manager startRangingBeaconsInRegion: (CLBeaconRegion*) region;
}
-(void) locationManager:(CLLocationManager*) manager didExitRegion:(CLRegion*) region{
NSLog(@"ExitRegion.");
manager stopRangingBeaconsInRegion: (CLBeaconRegion*) region;
}
-(void) locationManager:(CLLocationManager*) manager didRangeBeacons:(NSArray*)beacons inRegion:(CLBeaconRegion*) region{
NSLog(@"FindBeacon.");
}
I don't know if it will be helpful, but I will write a few things that I am interested in.
startRangingBeaconsInRegion
runs frequently
didDetermineState
and didEnterRegion
are referred to when entering the region from outside the iBeacon region.Also, if you start the app while you are already in the iBeacon region, only didDetermineState
is called.(didEnterRegion is not called)
Therefore, in my case, I only do startRangingBeaconsInRegion
when I pass CLRegionStateInside
in didDetermineState
.
About running requestStateForRegion
As for the series of events, I think the application has been started in the foreground.
In my case, when I started the app while I was already in the iBeacon area,
didDetermineState
was not called, so
requestStateForRegion
to detect iBeacon.
startRangingBeaconsInRegion
runs frequently
didDetermineState
and didEnterRegion
are referred to when entering the region from outside the iBeacon region.Also, if you start the app while you are already in the iBeacon region, only didDetermineState
is called.(didEnterRegion is not called)
So in my case, I only do startRangingBeaconsInRegion
when I go through didDetermineState
's CLRegionStateInside
.
About running requestStateForRegion
As for the series of events, I think the application has been started in the foreground.
In my case, when I started the app while I was already in the iBeacon area,
didDetermineState
was not called, so
requestStateForRegion
to detect iBeacon.
By the way, the iBeacon was not detected immediately after the terminal was turned on from the OFF state.
There seems to be no problem with the rest.
I hope it will be helpful.
© 2024 OneMinuteCode. All rights reserved.