1

我希望能够在初始化 my 时添加更多信息,例如数组或字符串,CLBeaconRegion以便可以在我的didRangeBeacons-method 中接收它。(不是主要的,也不是次要的)

目前,它看起来像这样:

_advertRegion = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid identifier:@"003-002-001"];

但我真的想像这样或类似的初始化它:

_advertRegion = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid identifier:@"003-002-001" setArrayOrSomething:myArray];

而且我显然应该能够从该地区获取信息,例如:

[region getArray];

当然,不一定非得如此,只要你有一个想法,我“需要”什么。

我试过的

  • 我试图通过一个设置/获取它objc_setAssociatedObject
  • 我试图通过一个setValue forKey
4

1 回答 1

1

我建议您只使用一个单独的 NSDictionary 实例,该实例与您在构建 CLBeaconRegion 时使用的标识符相同。

像这样:

// Make this a class variable, or make it part of a singleton object
NSDictionary *beaconRegionData = [[NSDictionary alloc] init];

// Here is the data you want to attach to the region
NSMutableArray *myArray = [[[NSMutableArray] alloc] init];

// and here is your region
_advertRegion = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid identifier:@"003-002-001"];

// attach your data to the NSDictionary instead
[beaconRegionData setValue:myArray forKey:_advertRegion.identifier];

// and you can get it like this    
NSLog(@"Here is my array: %@", [beaconRegionData valueForKey:_advertRegion.identifier]);
于 2013-10-29T03:23:40.330 回答