区域监控后台信标区域不起作用.



当应用程序在后台运行时,我在区域监控方面遇到问题。如果应用位于前台,则会调用区域进入和退出,但在后台时不会调用区域(有时它们会触发,但很少(。

信标区域监控如何适用于iOS 8.1.1?在后台时,区域是否应该在信标附近立即进入/退出射击?

我应该怎么做才能确保它有效?

Background ModesLocation UpdatesUses Bluetooth LE accessories必须打开才能进行后台信标监控才能工作吗?地理围栏在没有这些的情况下为我工作。

我已经做了什么:

  • 为每个区域设置这些:

    beaconRegion.notifyOnExit=YES; beaconRegion.notifyOnEntry=YES; beaconRegion.notifyEntryStateOnDisplay = YES;

  • 确保设置中的所有内容都井井有条(应用程序刷新等(

编辑:

我创建了一个新项目,但它仍然不起作用。代码如下:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

_locationManager = [[CLLocationManager alloc] init];
_locationManager.pausesLocationUpdatesAutomatically = NO;
_locationManager.desiredAccuracy = 25;
_locationManager.delegate = self;
[_locationManager requestAlwaysAuthorization];
[_locationManager startUpdatingLocation];
CLBeaconRegion* reg =[self prepareBeacon:@"here i put my UUID" :446 :2196];
[_locationManager startMonitoringForRegion:reg];
[_locationManager startRangingBeaconsInRegion:reg];
return YES;
}
-(CLBeaconRegion*)prepareBeacon:(NSString*)uuid :(int)maj :(int)min
{
NSString* identifier = [NSString stringWithFormat:@"%@,%d,%d", uuid, maj, min];
CLBeaconRegion *beaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:[[NSUUID alloc] initWithUUIDString:uuid] major:maj  minor:min identifier:identifier];
beaconRegion.notifyOnExit=YES;
beaconRegion.notifyOnEntry=YES;
beaconRegion.notifyEntryStateOnDisplay = YES;
return beaconRegion;
}
-(void)locationManager:(CLLocationManager *)manager didDetermineState:(CLRegionState)state           forRegion:(CLRegion *)region
{
}
-(void)locationManager:(CLLocationManager *)manager didEnterRegion:(CLRegion *)region
{
}
-(void)locationManager:(CLLocationManager *)manager didExitRegion:(CLRegion *)region
{
}
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
}
-(void)locationManager:(CLLocationManager *)manager didRangeBeacons:(NSArray *)beacons inRegion:(CLBeaconRegion *)region
{
}

一些附加信息:

  • 除了创建一个新的iOS8项目并添加我NSLocationAlwaysUsageDescription添加到*.plist文件的代码。
  • 我在didEnterRegiondidExitRegion中放置了断点.它在前台工作,在后台不起作用(iPhone在主屏幕或锁定(
  • 在 4S 和 iOS 8.1.1 上进行测试

您需要确保已在 CCLocationManager 下调用该方法

- (void) requestAlwaysAuthorization
这允许你的应用更新有关前台

和后台更改的信息,而以下行仅允许在前台时通知你的应用:

- (void) requestWhenInUseAuthorization

用户响应请求后,将使用更新的授权状态调用以下方法:

- (void) locationManager: (CLLocationManager*) manager
didChangeAuthorizationStatus: (CLAuthorizationStatus) status

源:https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/cl/CLLocationManager

答案是:后台区域监控对我们用户来说是一个谜。有时它会在一秒钟内启动,有时需要更长的时间。这取决于很多因素,但我的主要问题是我使用的是iPhone 4s。

也许这将在不浪费太多时间的情况下帮助任何人: 4s 在后台信标扫描时很糟糕

来源:在两款装有最新iOS和iPhone 6的4S手机上进行测试。 iPhone6在几秒钟内收到信标通知。

最新更新