当应用程序处于后台时,是否有合理的方法来检测万向节信标? 我目前的解决方案是在应用程序启动时启动Gimbal服务,并启动访问管理器。这样我每次进入灯塔区域时都会收到事件(即使在后台) 我相信必须有一个更优雅的解决方案,因为我无法始终保持服务的开始,寻找访问。此外,我观察到经理将在某些时候停止发送回调。
如果我总是希望了解信标访问(包括背景),您认为何时开始/停止服务以及启动/停止访问管理员会更好?
答案 0 :(得分:1)
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];
}
答案 1 :(得分:0)
查看文档中的后台监控部分。