当应用程序在后台运行时,是否有合理的方法来检测Gimbal信标?
我当前的解决方案是在应用启动时启动Gimbal服务,并启动访问管理器。这样,每次进入信标区域(即使是在后台),我都会收到事件。
我相信必须有一个更优雅的解决方案,因为我无法保持服务始终启动,寻找访问。另外,我观察到管理器将在某个时候停止发送回调。

如果我总是想知道信标访问(包括后台),您认为什么时候启动/停止服务和启动/停止访问管理器更好?

最佳答案

Gimbal VisitManager回调是在后台调用的,但是它们看起来有点不可靠。 (可能只是我的测试。)

在我的测试中(将Gimbal Series 10设置为默认设置),当我取出电池时,没有收到“didDepart”回调,但是当我放回电池时,我同时得到了这两个电池。走到20米之外的信标并不会再次触发它们,也许我没有等待足够长的时间,依此类推。

// 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];
}

您也可以将它们置于iBeacon模式https://stackoverflow.com/a/22666967中,然后使用标准回调。这对我来说是100%的时间,在我到达为iBeacon模式配置的信标附近后不久,调用didEnterRegion。
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];
}

关于ios - 云台背景检测,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/21401021/

10-10 01:41