iOS Question Get identifier of the Monitoring Region

Discussion in 'iOS Questions' started by Christian García S., Apr 3, 2019.

Similar threads

B4i Tutorial Background location tracking
B4i Tutorial iBeacons
B4i Tutorial Location & GPS
B4i Tutorial [Objective C] Writing libraries for B4i
B4i Tutorial Geofence - Monitoring a region
  1. Christian García S.

    Christian García S. Active Member Licensed User

    Hello,

    I have implemented two types of monitoring in my IOS app, the circular region and the region for beacons using this tutorial: https://www.b4x.com/android/forum/threads/geofence-monitoring-a-region.81464/# 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:

    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];
    }
    @end
    @interface B4ILocationManager (beacon)
    @end

    @implementation B4ILocationManager (beacon)
    - (void)locationManager:(CLLocationManager *)manager
            didRangeBeacons:(NSArray*)beacons
                   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.

    Code:
    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
            Globals.Push(
    "BeaconRegion",Globals.mensajeRegionBeacon,0)
        
    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:

    [​IMG]

    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.

    Thanks.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Please upload the project.
     
  3. Christian García S.

    Christian García S. Active Member Licensed User

    I attach the example project.

    Thanks
     

    Attached Files:

  4. Erel

    Erel Administrator Staff Member Licensed User

    Region type is Object. It has no methods.
    Code:
    Dim no As NativeObject = Region
    Log(no.GetField("identifier").AsString)
     
  5. Christian García S.

    Christian García S. Active Member Licensed User

    Thanks @Erel

    Can you help me with other thing, I receive a lot of PUSH when the user lock and unlock the phone or for another reason, I can change the configuration in monitoring only for sending one notification by day or something??

    upload_2019-4-9_17-51-4.png

    Thanks.
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    You should start a new thread for a new question.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice