【问题标题】:didRangeBeacons Delegate call CLProximityNear and CLProximityFar too fastdidRangeBeacons 委托调用 CLProximityNear 和 CLProximityFar 太快了
【发布时间】:2015-02-05 02:24:24
【问题描述】:

我想插入一个计时器以避免在“远”、“近”、“立即”状态之间切换。

我对“远”和“近”状态使用相同的视图,但我为即时状态推送一个新视图。

所以对于返回根目录的直接情况,我已经通过这样做找到了解决方案:

[self performSelector:@selector(patchSelectorPopToRoot) withObject:nil afterDelay:4];

如果我使用相同的视图,我该如何处理“近”和“远”状态?

这是代表:

-(void)beaconManager:(ESTBeaconManager *)manager
     didRangeBeacons:(NSArray *)beacons
            inRegion:(ESTBeaconRegion *)region
{
    // Descriptor on distance to sort the array of beacons by distance
    NSSortDescriptor *sortDescriptor;
    sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"distance" ascending:YES];
    NSArray *sortDescriptors = [NSArray arrayWithObject:sortDescriptor];

    // Sorting the array of beacons
    // Beacon array is sorted based on distance
    // Closest beacon is the first one
    self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];

    if([self.beaconsArray count] > 0)
    {

        if(!self.selectedBeacon)
        {
            // initialy pick closest beacon
            self.selectedBeacon = [beacons objectAtIndex:0];
            currentBeaconMinor = self.selectedBeacon.minor;
        }
        else
        {

            //Sorting the array of beacons
           self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];

           //Updating the selected beacon with the first element of the array (closest beacon)
           if(self.selectedBeacon != [beacons objectAtIndex:0] )
            {
                self.selectedBeacon = [beacons objectAtIndex:0];
                currentBeaconMinor = self.selectedBeacon.minor;
            }

        }

        // Switch on proximity of the closest beacon
        switch (self.selectedBeacon.proximity)
        {
            case CLProximityUnknown:
            {
                [self DoOnProximityUnknow];

                break;
            }
            case CLProximityImmediate:
            {
                [self DoOnProximityImmediate];

                break;
            }
            case CLProximityNear:
            {
                [self DoOnProximityNear];

                break;

            }
            case CLProximityFar:
            {
                [self DoOnProximityFar];

                break;
            }

            default:
                break;

        }
        self.beaconsArray = [beacons sortedArrayUsingDescriptors:sortDescriptors];
    }
}

这是我想使用计时器(Near)的方法。

-(void)DoOnProximityNear
{
    //Starting a timer

    //not working :
    //[NSTimer scheduledTimerWithTimeInterval:20 target:self selector:@selector(timerCalled) userInfo:nil repeats:NO];


    //not working
    /*
    double delayInSeconds = 20.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        NSLog(@"Do some work");
    });*/
}

我只想在我的“Near”方法中设置一个 20 秒的计时器。我想在返回“Far”之前至少停留 20 秒。

我应该在哪里插入这个计时器?我应该等待远信号,启动计时器并等待另一个远信号,还是应该在我到达附近时启动计时器?

请问我该如何解决这个问题?

提前感谢您的帮助。

【问题讨论】:

标签: ios objective-c timer location ibeacon


【解决方案1】:

在我过去的一项工作中,需要同样的东西。我希望以下一项对您有所帮助。在我的情况下,我的逻辑基于 RSSI(它也经常波动)

方式 1 为 CLProximityFar 和 CLProximityNear 放置一个计数器,并根据该触发动作,计算相同 Proximity 的连续出现次数,如果是,则考虑该 PROximity 并触发其动作。

方式 2 这完全基于 RSSI 值。为此,您需要使用 10-20 个连续 RSSI 值,取它们的平均值并在此基础上触发操作。

【讨论】:

  • 谢谢你的回答,你能分享一个例子吗?现在我使用带有计时器的 Paulw11 解决方案。当它检测到很远时,我启动一个计时器并检查我是否真的很远,如果我真的很远,我会更改设备上的视图。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-07-08
  • 2015-04-11
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多