2014-01-29 40 views
5

當使用簡單應用測試信標區域監控時,我似乎根據設備(不是設備型號,特定設備)得到非常不一致的結果。問題是,在requestStateForRegiondidEnterRegion在這些設備上根本沒有被調用之後,我沒有收到該區域的CLRegionStateInside狀態。 startRangingBeaconsinRegion:工作正常,但爲了節省電力並處理它,建議只在didEnterRegion:方法被調用時纔開始測距。我在6臺設備上進行了測試,並且它在一半(iPhone 5)上工作,並且不適用於一臺iPhone 5,一臺5S和一臺4SIBeacon區域監控在設備間不一致工作

我使用的信標是kontakt.io信標。

這是代碼來設置區域監測

self.locationManager = [[CLLocationManager alloc] init]; 

    self.locationManager.delegate = self; 



    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:BEACON_UUID]; 

    CLBeaconRegion *region = [[CLBeaconRegion alloc] initWithProximityUUID:uuid 

                   identifier:@"regionIdentifier"]; 

    region.notifyOnEntry = YES; 

    region.notifyOnExit = YES; 

    region.notifyEntryStateOnDisplay = YES; 



    [self.locationManager startMonitoringForRegion:region]; 

    [self.locationManager requestStateForRegion:region]; 

    //If I enable this line, ranging starts on all devices 

// [self.locationManager startRangingBeaconsInRegion:region]; 
+0

我相信你應該叫[_locationManager startMonitoringForRegion:區域]。不是startRangingBeaconsInRegion :. – Greg

+0

我確實會調用該方法,因爲您可以在我的帖子中看到。解決方案是讓用戶啓用後臺刷新,正如我在我的回答中提到的 – TimPelgrim

回答

4

我發現這個問題。顯然,要按照文檔中描述的方式使用iBeacons,用戶需要在「設置」中啓用「後臺刷新」設置。要檢查此設置我用下面的代碼片段:

if ([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusAvailable) { 

    NSLog(@"Background updates are available for the app."); 
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusDenied) 
{ 
    NSLog(@"The user explicitly disabled background behavior for this app or for the whole system."); 
}else if([[UIApplication sharedApplication] backgroundRefreshStatus] == UIBackgroundRefreshStatusRestricted) 
{ 
    NSLog(@"Background updates are unavailable and the user cannot enable them again. For example, this status can occur when parental controls are in effect for the current user."); 
} 

在此找到答案:Detecting user settings for Background App Refresh in iOS 7

4

監測可能不會有幾個原因的工作。一個是應用程序背景刷新已禁用,以節省您的電池。另一個是忽視確保您已經設置了正確的應用程序功能。

Background Modes

如果這不起作用有一個偉大的職位,你可以閱讀詳細說明所有項目的解決。

iBeacon StartMonitoringForRegion Doesn’t Work

+0

尼斯鏈接,後臺刷新模式測試指出我正確的方向 – dulgan