Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何检测哪个iBeacon超出范围?_Ios_Xcode_Cllocationmanager_Ibeacon - Fatal编程技术网

Ios 如何检测哪个iBeacon超出范围?

Ios 如何检测哪个iBeacon超出范围?,ios,xcode,cllocationmanager,ibeacon,Ios,Xcode,Cllocationmanager,Ibeacon,我正在使用CLLocationManager检测iOS应用程序中的iBeacons 我需要使用下面的方法来检测我的设备是否脱离信标区域 -(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion *)region 在我使用的三个iBeacon中,我如何检测设备超出范围的iBeacon区域 我尝试了下面的代码,但我没有得到大调和小调的值 - (void)locationManager:(CLLocati

我正在使用CLLocationManager检测iOS应用程序中的iBeacons

我需要使用下面的方法来检测我的设备是否脱离信标区域

-(void)locationManager:(CLLocationManager*)manager didExitRegion:(CLRegion   *)region
在我使用的三个iBeacon中,我如何检测设备超出范围的iBeacon区域

我尝试了下面的代码,但我没有得到大调和小调的值

- (void)locationManager:(CLLocationManager*)manager didEnterRegion: (CLRegion *)region
{
  CLBeaconRegion *beaconRegion = (CLBeaconRegion*) region;
  NSLog(@"%@",beaconRegion.major);
  NSLog(@"%@",beaconRegion.minor);
  NSLog(@"%@",beaconRegion.proximityUUID);

  NSString *str = [NSString stringWithFormat:@"Major:%@ Minor:%@",beaconRegion.major,beaconRegion.minor];
  UILocalNotification *notification = [UILocalNotification new];
  notification.alertBody = str;
  [[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

您可以检查RSSI的值,该值给出了当前连接信标的信号强度值。到某一点时,信号强度继续下降,如果范围内有其他可用信标,则设备可能连接到其他信标

总之,您可以使用RSSI值检查信号强度。

尝试此代码

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

    if (beacons.count) {
        CLBeacon * beacon = beacons[2]; // If you want to detect the range of third beacon 

        switch (beacon.proximity) {

            case CLProximityUnknown:
                NSLog(@"Unknown");
                break;
            case CLProximityFar:
                NSLog(@"Far");
                break;
            case CLProximityNear:
                NSLog(@"Near");
                break;
            case CLProximityImmediate:
                NSLog(@"Immediate");
            default:
                NSLog(@"No beacons found");
                break;
            }
        }
    }

如果它位于CLProximitUnknown内部,您可以使用CoreLoviation监视API知道信标正在超出范围

,您无法判断受监视的
CLBeaconRegion
中的单个信标何时超出范围。当所有信标都退出该区域时,您只会收到一次对
didExit
的回调。您无法读取单个信标的主字段和次字段——您只能访问用于设置监视的区域对象,在您的示例中,这些字段可能为零

两种常见的解决方法:

  • 定义多个
    CLBeaconRegion
    s,使每个区域只匹配一个信标。
    (填充主信标和次信标)。主要限制是一次只能监视20个区域
  • 使用测距API。您可以调用
    [location?Manager StarTrangBeacon sInRegion:region]
    然后每秒收到一次回调,在该间隔内检测到所有信标,并填充所有标识符。我通常将其存储在由信标标识符键入的
    NSDictionary
    中,并保存上次检测到信标的时间
    NSDate
    。然后我会定期寻找过去15秒钟内没有看到的信标,我知道这些信标已经退出
第二种方法的缺点是,您只能在应用程序位于前台时以及移动到后台后的几秒钟内进行测距