我有一個區域監控問題,而應用程序在後臺。 如果應用程序處於前臺,但進入和退出區域被調用,但不在背景中(有時會觸發,但很少)。區域監控信標區域在背景不起作用
信標區域監控如何在iOS 8.1.1上工作?當在烽火臺附近時,區域應當立即進入/退出火場?
我應該怎麼做才能確保它能正常工作?
做Background Modes
:Location Updates
或Uses Bluetooth LE accessories
必須開啓背景信標監測工作? GeoFencing在沒有這些的情況下爲我工作。
我已經做了:
設置這些每一個區域:
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文件。 - 我把斷點放在
didEnterRegion
和didExitRegion
。它工作在前臺,而在背景(iPhone在主屏幕或鎖定)不起作用 - 測試4S上,的iOS 8.1.1
無需爲iBeacons設置背景模式 – 2014-12-12 08:36:19