ios - 云台背景检测

标签 ios background bluetooth

当应用程序处于后台时,是否有合理的方法来检测 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/

相关文章:

iphone - 未调用 UIView layoutSubviews

objective-c - 每十秒检查一次后台状况并发送通知

java - 无法确定空指针异常背后的原因

bluetooth - 有没有办法在 Android Instant App 中进行蓝牙扫描?

ios - user_photos 在 Swift 中访问列表

ios - 在 Xcode/Swift 中使用预设置 View

ios - 在 NSDictionary* 类型的对象上找不到读取数组元素的预期方法

html - 仅在特定区域不透明度

ios - 应用程序在 iOS 10 上终止,恕不另行通知

java - android Java - 当 Activity 重新启动时,Textview 不附加文本