gpt4 book ai didi

ios - 测距信标仅在应用程序运行时有效?

转载 作者:IT王子 更新时间:2023-10-29 07:59:23 24 4
gpt4 key购买 nike

当应用程序未运行时,我很难让它正常工作。我实现了 locationManager:didRangeBeacons:inRegion: 并在应用程序在前台或后台运行时调用它,但是当我退出应用程序并锁定屏幕时它似乎没有做任何事情。位置服务图标消失了,我永远不知道我进入了信标范围。 LocalNotification 是否仍然有效?

我在后台模式 (XCode 5) 中选择了位置更新和使用蓝牙 LE 配件,我认为我不需要它们。

非常感谢任何帮助。

-(void)watchForEvents { // this is called from application:didFinishLaunchingWithOptions
id class = NSClassFromString(@"CLBeaconRegion");
if (!class) {
return;
}

CLBeaconRegion * rflBeacon = [[CLBeaconRegion alloc] initWithProximityUUID:kBeaconUUID identifier:kBeaconString];
rflBeacon.notifyOnEntry = YES;
rflBeacon.notifyOnExit = NO;
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
[self.locationManager startRangingBeaconsInRegion:rflBeacon];
[self.locationManager startMonitoringForRegion:rflBeacon];
}

-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region {
if (beacons.count == 0 || eventRanged) { // breakpoint set here for testing
return;
}

eventRanged = YES;
if (backgroundMode) { // this is set in the EnterBackground/Foreground delegate calls
UILocalNotification *notification = [[UILocalNotification alloc] init];
notification.alertBody = [NSString stringWithFormat:@"Welcome to the %@ event.",region.identifier];
notification.soundName = UILocalNotificationDefaultSoundName;
[[UIApplication sharedApplication] presentLocalNotificationNow:notification];
}

// normal processing here...
}

最佳答案

监控可以启动未运行的应用程序。测距不能。

<德尔>监控启动您的应用程序的关键是在您的 CLBeaconRegion 上设置这个记录不完整的标志:region.notifyEntryStateOnDisplay = YES; 即使在完全重启手机后,这也可以在区域转换时启动您的应用程序。但有几点需要注意:

  1. 您的应用仅在后台启动几秒钟。 (尝试将 NSLog 语句添加到 applicationDidEnterBackground 和 AppDelegate 中的其他方法以查看发生了什么。)
  2. iOS 可以从容地决定您是否进入了 CLBeaconRegion。我看到最多需要四分钟。

就测距而言,即使您无法通过测距唤醒您的应用,您也可以让您的应用同时进行监测和测距。如果监控唤醒您的应用程序并将其置于后台几秒钟,则范围回调会立即启动。这使您有机会在应用仍在运行时执行任何快速测距操作。

编辑:进一步调查证明 notifyEntryStateOnDisplay 对后台监控没有影响,因此无论您是否有此标志,以上内容都应该有效。参见 this detailed explanation and discussion of delays you may experience

关于ios - 测距信标仅在应用程序运行时有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19141779/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com