区域监视背景中的信标区域不工作 [英] Region monitoring beacon regions in background not working

查看:99
本文介绍了区域监视背景中的信标区域不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在应用程序处于后台时遇到区域监控问题。
如果应用程序位于前台,则区域进入和退出被调用,但在后台不进行调用(有时它们会触发但非常罕见)。

I have a problem with region monitoring while the app is in background. Region enters and exits get called if the app is in foreground, but doesn't while in the background (sometimes they fire but very rarely).

如何iOS 8.1.1的信标区域监控工作?当在背景中处于Beacon接近状态时,区域是否应立即进入/退出?

How does beacon region monitoring work for iOS 8.1.1 ? Should region enters/exit fire instantly when in Beacon proximity while in background ?

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

What should I do to make sure it works ?

执行后台模式位置更新使用蓝牙LE附件必须打开后台信标监控才能工作? GeoFencing在没有这些的情况下为我工作。

Do Background Modes : Location Updates or Uses Bluetooth LE accessories have to be on for background beacon monitoring to work ? GeoFencing worked for me without having these on.

我已经做过的事情:


  • 为每个地区设置以下内容:

  • set these for every region:

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

编辑:

我创建了一个新项目但它仍然没有工作。这是代码:

I've created a new project and it still doesn't work. Here's the code:

- (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文件。

  • 我将断点放在 didEnterRegion didExitRegion 。它在前台工作,在后台无法工作(主屏幕上的iPhone或锁定)

  • 在4S,iOS 8.1.1上测试

  • Except creating a fresh iOS8 project and adding code I've added NSLocationAlwaysUsageDescription to *.plist file.
  • I put breakpoints in didEnterRegion and didExitRegion. It works in foreground, doesn't work while in background (iPhone in home screen or locked)
  • Testing on 4S, iOS 8.1.1

推荐答案

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

The answer is: background region monitoring is a mystery to us users. Sometimes it fires up in a second, sometimes it takes longer. It depends on a lot of factors but my main problem was that I was using iPhone 4s.

也许这会帮助任何人而不会失去这么多时间: 4s在背景信号扫描时很糟糕

Maybe this will help anyone without losing so much time: 4s sucks at background beacons scanning

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

source: tested on two 4S phones with latest iOS and iPhone 6. iPhone6 gets beacon notifications in a matter of seconds.

这篇关于区域监视背景中的信标区域不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆