代码之家  ›  专栏  ›  技术社区  ›  Simant

n根据UUID、主要和次要提升异常预测筛选信标

  •  2
  • Simant  · 技术社区  · 6 年前

    我有一个 信标 数组有一个CLBeacon集合,我只想得到与NSPredicate中给定的uuid、major和minor匹配的信标。下面是对象C中的代码,该代码由于谓词中的UUID而生成异常。如果我从查询中删除uuidpreditate,代码就可以正常工作。

     - (void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray<CLBeacon *> *)beacons inRegion:(CLBeaconRegion *)region{
    
            NSPredicate *uuidPredicate = [NSPredicate predicateWithFormat:@"uuid.UUIDString == [c] %@", @"03672ce6-9272-48ea-ba54-0bf679217980"];
           //NSPredicate *uuidPredicate = [NSPredicate predicateWithFormat:@"uuid == %@", @"03672ce6-9272-48ea-ba54-0bf679217980"];
            NSPredicate *majorPredicate = [NSPredicate predicateWithFormat:@"major = %ld", 1];
            NSPredicate *minorPredicate = [NSPredicate predicateWithFormat:@"minor = %ld", 3];
    
            NSPredicate *compoundPredicate = [NSCompoundPredicate andPredicateWithSubpredicates:@[uuidPredicate, majorPredicate, minorPredicate]];
    
            NSArray *pointABeacon = [beacons filteredArrayUsingPredicate:compoundPredicate];   
    
        }
    

    信标阵列类似于

    beacons (
        "CLBeacon (uuid:03672CE6-9272-48EA-BA54-0BF679217980, major:1, minor:1, proximity:1 +/- 0.07m, rssi:-61)",
        "CLBeacon (uuid:03672CE6-9272-48EA-BA54-0BF679217980, major:1, minor:2, proximity:1 +/- 0.07m, rssi:-62)",
        "CLBeacon (uuid:03672CE6-9272-48EA-BA54-0BF679217981, major:1, minor:3, proximity:2 +/- 1.64m, rssi:-53)"
    )
    

    例外是

    ***由于未捕获的异常“NSUnknownKeyException”而终止应用程序,原因:“[<CLBeacon 0x1c401c410>valueForUndefinedKey:]:此类是 密钥uuid不符合密钥值编码

    如何用uuid、major和minor三个参数过滤数组?

    1 回复  |  直到 6 年前
        1
  •  1
  •   Larme    6 年前

    错误很明显: 一个 CLBeacon 对象没有名为 uuid .

    当你打印一个 灯塔 对象,您可能会看到“uuid”,但这不是属性的真实名称,而是 proximityUUID

    所以:

    NSPredicate *uuidPredicate = [NSPredicate predicateWithFormat:@"uuid.UUIDString == [c] %@", @"03672ce6-9272-48ea-ba54-0bf679217980"];
    

    应该是:

    NSPredicate *uuidPredicate = [NSPredicate predicateWithFormat:@"proximityUUID.UUIDString == [c] %@", @"03672ce6-9272-48ea-ba54-0bf679217980"];
    
    推荐文章