OGeek|极客世界-中国程序员成长平台

标题: ios - 云台背景检测 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 18:17
标题: ios - 云台背景检测

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

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



Best Answer-推荐答案


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

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

// Definitely can trigger from background
- (void)didArriveFYXVisit *)visit;
- (void)didDepartFYXVisit *)visit;

// Handy code to discover when the background method is called
- (void)didArriveFYXVisit *)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)locationManagerCLLocationManager *)manager didEnterRegionCLRegion *)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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4