背景区域监控信标区域不工作
在应用程序处于后台时,我遇到了区域监视问题。 如果应用程序处于前台,区域进入和退出被调用,但不在后台(有时它们会触发,但很less)。
信标区域监视如何在iOS 8.1.1上工作? 当在烽火台附近时,地区是否应该立即进入/退出火场?
我该怎么做,以确保它的工作?
做Background Modes
: Location Updates
或Uses Bluetooth LE accessories
必须打开后台信标监测工作? GeoFencing为我工作,而没有这些。
我已经做了什么:
-
为每个地区设置这些:
beaconRegion.notifyOnExit=YES; beaconRegion.notifyOnEntry=YES; beaconRegion.notifyEntryStateOnDisplay = YES;
- 确保设置中的一切都是按顺序的(应用程序刷新等)
编辑:
我创build了一个新的项目,但仍然无法正常工作。 代码如下:
- (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 { }
一些额外的信息:
- 除了创build一个新的iOS8项目和添加代码,我已经添加
NSLocationAlwaysUsageDescription
* .plist文件。 - 我把断点放在
didEnterRegion
和didExitRegion
。 它在前台工作,在后台工作(主屏幕中的iPhone或locking) - testing4S,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手机上进行testing。iPhone6在几秒钟内即可获得信标通知。