Objective c 向区域添加其他信息。伊贝肯

Objective c 向区域添加其他信息。伊贝肯,objective-c,core-location,cllocationmanager,core-bluetooth,ibeacon,Objective C,Core Location,Cllocationmanager,Core Bluetooth,Ibeacon,我希望在初始化CLBeaconRegion时能够添加更多信息,如数组或字符串,以便可以通过didRangeBeacons-方法接收它。(非大调或小调) 目前,情况是这样的: _advertRegion = [[CLBeaconRegion alloc] initWithProximityUUID:_uuid identifier:@"003-002-001"]; 但我真的想像这样或类似地初始化它: _advertRegion = [[CLBeaconRegion alloc] initWith

我希望在初始化
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\u setassociated对象设置/获取它
  • 我试图通过
    setValue-forKey设置它

我建议您只使用一个单独的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]);

我建议您只使用一个单独的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]);

作为简化,CLBeacon符合NSCopying协议,因此据我所知,它可以直接用作字典中的密钥。作为简化,CLBeacon符合NSCopying协议,因此据我所知,它可以直接用作字典中的密钥。