gpt4 book ai didi

ios - didEnterRegion 仅在设备唤醒时触发

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:23:35 25 4
gpt4 key购买 nike

我在我的应用中使用由 iBeacon 触发的本地通知。只要 iPhone 处于事件状态,它在前台和后台都能正常工作,但在大约 15 分钟不活动或重启后不会触发 didEnterRegion

然后它只会在使用主页按钮或 sleep 按钮唤醒 iPhone 时再次触发,但我希望 didEnterRegion 在 iPhone 放在口袋里 15 分钟或更长时间时“触发”也进入该地区。

这可能吗?如果是,如何?

后台模式> 位置更新被禁用

部分代码:

.h

@property (strong, nonatomic) CLBeaconRegion *beaconRegion;
@property (strong, nonatomic) CLLocationManager *locationManager;

.m

- (void)start {
self.beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid identifier:@"com.bla.bla"];

self.beaconRegion.notifyOnEntry = YES;
self.beaconRegion.notifyOnExit = YES;
self.beaconRegion.notifyEntryStateOnDisplay = YES;
self.locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers;
[self.locationManager startUpdatingLocation];

[self.locationManager startMonitoringForRegion:self.beaconRegion];
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
[self.locationManager requestStateForRegion:self.beaconRegion];
}

- (void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region {
[self.locationManager startRangingBeaconsInRegion:self.beaconRegion];
}

-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region {
[self.locationManager stopRangingBeaconsInRegion:self.beaconRegion];
}

- (void)locationManager:(CLLocationManager *)manager monitoringDidFailForRegion:(CLRegion *)region withError:(NSError *)error
{
NSLog(@"%@", [error localizedDescription]);
}

-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state forRegion:(CLRegion *)region {
if (state == CLRegionStateInside) {
[manager startRangingBeaconsInRegion:self.beaconRegion];
} else {
[manager stopRangingBeaconsInRegion:self.beaconRegion];
}
}

最佳答案

我不确定这里发生了什么,但问题中描述的体验与我在多台设备上测试时看到的不一致。发布设置它的代码可能有助于找到一些答案。

在几个应用程序中,我已经能够获得后台 didEnterRegion 回调,即使在超过 15 分钟不活动而没有按下肩键或主页按钮之后也是如此。为此,我不必设置任何背景模式。 (如果您在后台模式位置更新设置不必要的情况下将其提交给商店,Apple 实际上会拒绝您的应用程序。)

iOS 7.1 中有一个错误,它会在启动后的某个时刻停止 iBeacon 检测,所以这可能就是这种情况下发生的情况。详情为here .不幸的是,测试这个假设将需要您唤醒屏幕以关闭和打开蓝牙以清除条件,并且这将唤醒您的屏幕并让您无论如何退出该区域。也许您可以尝试设置 beaconregion.notifyEntryStateOnDisplay=NO,重新创建此条件,然后尝试循环蓝牙以查看是否收到通知。您还可以使用现成的信标扫描应用程序,例如 Locate for iBeacon查看您的设备在进入此状态后是否能够完全检测到 iBeacon,如果您无法检测到 iBeacon,则仅循环到蓝牙。

关于ios - didEnterRegion 仅在设备唤醒时触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23390832/

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