2

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

然后它只会在使用主页按钮或睡眠按钮唤醒 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];
    }
}
4

1 回答 1

1

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

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

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

于 2014-04-30T15:42:02.613 回答