I have maintained beacon information in plist and when I initialized the CLBeaconRegion, I am getting different Major and Minor values for the region. After doing NSLog I came to know that Major and Minor values holding in an NSString are giving me the correct values as in the plist and when I convert the values to CLBeaconMajorValue or CLBeaconMinorValue or NSInteger the values are different. I have changed both NSString and Number datatype in plist but with no luck. Why is this happening? Could you please help me to rectify this issue?
NSUInteger major = (NSUInteger) [beaconInfo objectForKey:@"major"];
NSUInteger minor = (NSUInteger)[beaconInfo objectForKey:@"minor"];
NSLog(@"major : %ld, minor : %ld", major, minor);
NSString *majorString = [beaconInfo objectForKey:@"major"];
NSString *minorString = [beaconInfo objectForKey:@"minor"];
NSLog(@"major : %@, minor : %@", majorString, minorString);
NSLog(@"major : %hu, minor : %hu", (CLBeaconMajorValue)majorString, (CLBeaconMinorValue) minorString);
CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID: [[NSUUID alloc] initWithUUIDString: [beaconInfo objectForKey:@"uuid"]] major: (CLBeaconMajorValue) [beaconInfo objectForKey:@"major"] minor: (CLBeaconMinorValue) [beaconInfo objectForKey:@"minor"] identifier:@"com.test"];
NSLog(@"%@", region);
The plist is
NSLog generated are
major : -5764607523034234861, minor : -5764607523034234861
major : 1, minor : 1
major : 19, minor : 19
CLBeaconRegion (identifier:'com.test', uuid:03672CE6-9272-48EA-BA54-0BF679217980, major:19, minor:19)
In your plist, the value is typed as Number
, so the values are NSNumber
when read.
So [beaconInfo objectForKey:@"major"]
is a NSNumber
object.
So you need to write NSUInteger major = [(NSNumber *)[beaconInfo objectForKey:@"major"] integerValue];
which can be simplified with NSUInteger major = [[beaconInfo objectForKey:@"major"] integerValue];
Same for minor.
Just check that all the values major/minor in your .plist are of type Number.