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:
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.
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.
Thanks.
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:
B4X:
#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.
B4X:
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:
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.