2

Is there a reasonable way to detect Gimbal beacons, when the app is in background?
My current solution is to start the Gimbal service when the app launches and also start the visit manager. That way I receive events each time I get into the area of a beacon (even in background).
I believe there must be a more elegant solution because I cannot keep the service always started, searching for visits. Also, I observed that the manager will stop sending callbacks at some point.

When do you think is better to start/stop the service and start/stop the visit manager if I always want to be informed about beacons visits (background included)?

Mihai Popa
  • 892
  • 1
  • 8
  • 25

2 Answers2

1

The Gimbal VisitManager callbacks are called in the background, but they seem a touch unreliable. (Might just be my testing.)

In my testing (setup Gimbal Series 10 to default settings) when I removed the battery I didn't get a "didDepart" callback, but when I put the battery back in I got both at the same time. Walking the beacon 20 meters away didn't trigger them again, maybe I didn't wait long enough, etc.

// Definitely can trigger from background
- (void)didArrive:(FYXVisit *)visit;
- (void)didDepart:(FYXVisit *)visit;

// Handy code to discover when the background method is called
- (void)didArrive:(FYXVisit *)visit {
    UILocalNotification* localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
    localNotification.alertBody = @"Gimbal Arrive Visit";
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}

You can also put them in iBeacon mode https://stackoverflow.com/a/22666967 and then use the standard callback. This works 100% of the time for me, calling the didEnterRegion shortly after I arrive near a beacon configured for iBeacon mode.

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;

// Start monitoring the region (called on app start, etc.)
NSUUID *frontDoorID = [[NSUUID alloc] initWithUUIDString:@"FC3DAF5A-6223-4D71-9DCD-452DC95E6CDF"];
CLBeaconMajorValue major = 1000;
CLBeaconMinorValue minor = 2000;

CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:frontDoorID
                                                                      major:major
                                                                      minor:minor
                                                                 identifier:@"entrance"];
[self.locationManager startMonitoringForRegion:beaconRegion];


// Called even in the background
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
    NSLog(@"Arrived at Beacon");

    // Fire a local notification to show an indication that the background event happened
    UILocalNotification* localNotification = [[UILocalNotification alloc] init];
    localNotification.fireDate = [NSDate dateWithTimeIntervalSinceNow:1];
    localNotification.alertBody = @"Beacon Found";
    localNotification.timeZone = [NSTimeZone defaultTimeZone];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
}
Community
  • 1
  • 1
owenfi
  • 2,471
  • 1
  • 24
  • 37
0

Check out the background monitoring section in the docs.

https://gimbal.com/doc/proximity/ios.html#background

jspooner
  • 10,975
  • 11
  • 58
  • 81