向区域添加其他信息。 iBeacons

时间:2013-10-28 23:28:13

标签: objective-c core-location cllocationmanager core-bluetooth ibeacon

我希望能够在初始化CLBeaconRegion时添加更多信息,例如数组或字符串,以便我可以通过didRangeBeacons方法接收它。 (主要或次要)

此刻,它看起来像这样:

_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
  • 进行设置

1 个答案:

答案 0 :(得分: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]);
相关问题