iOS Question Get identifier of the Monitoring Region

Christian García S.

Active Member
Licensed User

I have implemented two types of monitoring in my IOS app, the circular region and the region for beacons using this tutorial: post-654118

Based on the @Erel help I have been able to mix the two monitoring so you can determine which region I am entering, I am using the following code:

#if objc
- (NSObject*)createCircularRegdion:(double)lat :(double)lon :(double)radius :(NSString*)identifier {
   return [[CLCircularRegion alloc] initWithCenter:CLLocationCoordinate2DMake(lat, lon) radius:(CLLocationDistance)radius identifier:identifier];
@interface B4ILocationManager (beacon)

@implementation B4ILocationManager (beacon)
- (void)locationManager:(CLLocationManager *)manager
               inRegion:(CLBeaconRegion *)region {
              if (beacons.count > 0) {
                [B4IObjectWrapper raiseEvent:self :@"_didrangebeacons:"
                    :@[[B4IObjectWrapper createWrapper:[B4IList new] object:beacons]]];
- (void)locationManager:(CLLocationManager *)manager
  didExitRegion:(CLRegion *)region {
      [B4IObjectWrapper raiseEvent:self :@"_regionexit:" :@[region]];
- (void)locationManager:(CLLocationManager *)manager
  didEnterRegion:(CLRegion *)region {
      [B4IObjectWrapper raiseEvent:self :@"_regionenter:" :@[region]];
- (void)locationManager:(CLLocationManager *)manager
monitoringDidFailForRegion:(CLRegion *)region
  withError:(NSError *)error {
   NSLog(@"Error: %@", error);
   [B4IObjectWrapper raiseEvent:self :@"_statechanged:" :@[@(3), region]];
- (void)locationManager:(CLLocationManager *)manager
didStartMonitoringForRegion:(CLRegion *)region {
   NSLog(@"Start monitoring: %@", region);
- (void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)State forRegion:(CLRegion *)region {
  NSLog(@"didDetermineState: %@", @(State));
  [B4IObjectWrapper raiseEvent:self :@"_statechanged::" :@[@(State), region]];
#End If

One of the changes made to the LocManager_StateChanged function is to include the region object, so that it can determine the type of region, circular region or beacon and its identifier.

Sub LocManager_StateChanged(State As Int, Region As Object)
    '0 = unknown, 1 = inside, 2 = outside
    Log("Region: " & GetType(Region) & ", State: " & State & ", " & $"$Time{DateTime.Now}"$)
    If State = 1 And GetType(Region) = "CLBeaconRegion" Then
    End If
    If    State = 1 And GetType(Region) = "CLCircularRegion" Then
        GetGeofenceCampaign("") ' here I need Region.GetField ("identifier")
    End If
End Sub

But when I try to identify the region with Region.GetField ("identifier") -> Geofence - Monitoring a region, I can not convert it to a string:


I need to know the identifier, so that according to that identifier I receive a message with the name of the place with additional data.

I have B4i 5.51.